users@glassfish.java.net

EntityManager in EJB not injected in overloaded method

From: <forums_at_java.net>
Date: Tue, 23 Aug 2011 07:07:11 -0500 (CDT)

Howdy Guys!

I'm facing a problem with injection of an EntityManager in my EJB.
It works fine when there are no overloaded methods, but as soon as I add such
method, the EntityManager within the method results in '*null*'.
I've provided a test project (using Arquillian) which I attach to this post -
below you can see the class under test (simplified for the sake of
brevity): 

*package* com.test;   *import* java.io.Serializable;   *import*
javax.persistence.EntityManager; *import*
javax.persistence.PersistenceContext;   *public* *class* CRUDBean<K
*extends* Serializable, T *extends* Serializable> {       
@PersistenceContext      *private* EntityManager em;        *public*
T create(T entity) {           // This results to properly injected
EM.           System.out.println("!!!! Create EM: " +
em);                    *return* *null*;      }  
     *public* Object find(K id, Class<T> entityClass) {
          *return* *null*;      }        *public* Object
find(String parameters, Class<T> entityClass) {           // Results
to null. When the above (overloaded) method is removed, it results to
properly injected EM.           System.out.println("!!!! Find EM: "
+ em);                           *return* *null*;
     } }
I've tested this case using Glassfish 3.1 embedded and remote. In both cases
the 'em' in find method is null.

Is this the appropriate behaviour?

Thanks in advance for your help!
Cheers!


--
[Message sent by forum member 'PedroKowalski']
View Post: http://forums.java.net/node/836240