-
1. Re: Entity Manager Producer Revisited
nickarls Mar 1, 2010 10:26 PM (in response to jpleed3.john.leediii.minitmarkets.com)Hmm. Can you try it in a JBoss AS 6.0.0.M2? Just trying to pinpoint if it's in Weld or the GF - Weld integration for @PersistenceContext resolves
-
2. Re: Entity Manager Producer Revisited
jpleed3.john.leediii.minitmarkets.com Mar 1, 2010 10:36 PM (in response to jpleed3.john.leediii.minitmarkets.com)I think that's going to take a while... I've never used JBoss.
-
3. Re: Entity Manager Producer Revisited
nickarls Mar 1, 2010 10:55 PM (in response to jpleed3.john.leediii.minitmarkets.com) -
4. Re: Entity Manager Producer Revisited
gavin.king Mar 2, 2010 2:45 AM (in response to jpleed3.john.leediii.minitmarkets.com)I would take that as a bug in GlassFish.
-
5. Re: Entity Manager Producer Revisited
chasetec Mar 2, 2010 7:20 AM (in response to jpleed3.john.leediii.minitmarkets.com)Page 28 of the CDI spec states:
The container is not required to support resources with scope other than @Dependent. Portable applications should not define resources with any scope other than @Dependent.
I tested an EntityManager and EntityManagerFactory producer with GlassFish and Weld 1.0 and unless I use (or default) my producer to @Dependent I get
org.jboss.weld.NullInstanceException: WELD-000044 Unable to obtain instance from org.jboss.weld.bean
. Using @Dependent makes it work fine. -
6. Re: Entity Manager Producer Revisited
jpleed3.john.leediii.minitmarkets.com Mar 3, 2010 6:42 PM (in response to jpleed3.john.leediii.minitmarkets.com)That's odd... I submitted this reply yesterday and it didn't take.
I tested the combinations of @Dependent with this and think I covered it. When tried field producers with dependent scope by default or with @Dependent on the bean or the fields, I got a WELD-000044 on page load. When I tried the same thing but with method producers, I got a NullPointerException instead.
Either way, it doesn't look like the resource is getting injected by the container.
-
7. Re: Entity Manager Producer Revisited
chasetec Mar 3, 2010 8:22 PM (in response to jpleed3.john.leediii.minitmarkets.com)Stupid question: Are you sure it is a CDI/Weld issue? Can you do a standard EE injection of @PersistenceUnit(unitName="IntranetPU") EntityManagerFactory entityManagerFactory; ? Add a servlet or ejb to your project to test with.
Can you show your code with the dependent producer and the injection point? -
8. Re: Entity Manager Producer Revisited
jpleed3.john.leediii.minitmarkets.com Mar 3, 2010 8:45 PM (in response to jpleed3.john.leediii.minitmarkets.com)It's not a stupid question. I was a PC tech years ago and with some people you couldn't even take it for granted that the machine was on.
I had everything set up on the standard EE injection before with Weld enabled. There were a couple of times when I switched back to it when having trouble with this issue.
Like I said, I tried plenty of variations for the producer. There's the method:
@PersistenceContext(unitName="IntranetPU") EntityManager entityManager; @Produces @IntranetDatabase public EntityManager produceEntityManager() { return entityManager; } public void disposeEntityManager(@Disposes @IntranetDatabase EntityManager em) {}
and the field:
@Produces @IntranetDatabase @PersistenceContext(unitName="IntranetPU") EntityManager entityManager;
I've tried @Dependent on the field / method, on the bean and no where at all. None of them work.
As for the injection points, I have them in multitude of locations: @SessionScoped backing beans, @ConversationScoped backing beans, JAX-RS resources, EJB's... if the container creates it, I inject into it! The vast majority (if not all) of the injection points for the qualifier are:
@Inject @IntranetDatabase EntityManager em;
-
9. Re: Entity Manager Producer Revisited
chasetec Mar 3, 2010 11:42 PM (in response to jpleed3.john.leediii.minitmarkets.com)Still working for me on GlassFish Full Profile w/ Weld 1.0.
Your Producer class itself is dependent scope right?
@IntranetDatabase is just a qualifier and not a stereotype correct?
If you want, put together a small project for download that has the problem and I'll test.
Did you patch the GlassFish code yourself to get 1.0.1? I'm starting to wonder if the problem is only a 1.0.1 and GFv3 issue....
-
10. Re: Entity Manager Producer Revisited
jpleed3.john.leediii.minitmarkets.com Mar 4, 2010 4:42 PM (in response to jpleed3.john.leediii.minitmarkets.com)Yes, I patched the integration module to get 1.0.1 to work. It's only a two line fix: https://glassfish.dev.java.net/issues/show_bug.cgi?id=11435
I tested every @Dependent use I could think of, on the bean, on the producer, by default with no annotation. Results only differed with using a field or method producer.
My qualifier is:
@Qualifier @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) public @interface IntranetDatabase {}
Like I said, if I just annotate the bean @Stateless everything works fine.
-
11. Re: Entity Manager Producer Revisited
jpleed3.john.leediii.minitmarkets.com Mar 4, 2010 5:30 PM (in response to jpleed3.john.leediii.minitmarkets.com)Okay, I think I understand what the problem is. I keep my entity classes along with that producer and qualifier in a common jar to use in my applications. If I move the producer and qualifier into the war's classes, then @Dependent works fine.
So, why doesn't resource injection work for an @Dependent bean in a bean archive?
Before anyone asks: yes, the archive does have a beans.xml in it; if it didn't the @Stateless version wouldn't work either.
-
12. Re: Entity Manager Producer Revisited
pmuir Mar 9, 2010 11:43 AM (in response to jpleed3.john.leediii.minitmarkets.com)
John Leed wrote on Mar 04, 2010 17:30:
Okay, I think I understand what the problem is. I keep my entity classes along with that producer and qualifier in a common jar to use in my applications. If I move the producer and qualifier into the war's classes, then @Dependent works fine.
So, why doesn't resource injection work for an @Dependent bean in a bean archive?
Before anyone asks: yes, the archive does have a beans.xml in it; if it didn't the @Stateless version wouldn't work either.This (not enabling the common jar) is a bug in GlassFish, please file an issue in their issue tracker. I know GlassFish has a number of issues around what is a bean archive...
-
13. Re: Entity Manager Producer Revisited
pmuir Mar 9, 2010 11:55 AM (in response to jpleed3.john.leediii.minitmarkets.com)
Matthieu Heimer wrote on Mar 02, 2010 07:20:
Page 28 of the CDI spec states:The container is not required to support resources with scope other than @Dependent. Portable applications should not define resources with any scope other than @Dependent.
I tested an EntityManager and EntityManagerFactory producer with GlassFish and Weld 1.0 and unless I use (or default) my producer to @Dependent I getorg.jboss.weld.NullInstanceException: WELD-000044 Unable to obtain instance from org.jboss.weld.bean
. Using @Dependent makes it work fine.Matthieu, could you file an issue for this one, we should at least give you a nicer error message that explains the problem properly!
-
14. Re: Entity Manager Producer Revisited
jpleed3.john.leediii.minitmarkets.com Mar 9, 2010 2:44 PM (in response to jpleed3.john.leediii.minitmarkets.com)
Pete Muir wrote on Mar 09, 2010 11:43:
This (not enabling the common jar) is a bug in GlassFish, please file an issue in their issue tracker. I know GlassFish has a number of issues around what is a bean archive...Thanks for the info Pete. I filed https://glassfish.dev.java.net/issues/show_bug.cgi?id=11640 last week for the @Dependent em producer. From the other issues, it does seem it has trouble with bean archive definition. Is that tested for in the TCK?