Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

EntityManager null - running JBoss, EJB3, initiated by Web Service

843830Apr 18 2007 — edited Apr 26 2007
Hi,

I'm having an issue deploying to JBoss 4.0.5-ejb3. When I try to inject my EntityManager in my code:
@PersistenceContext EntityManager em;
it is always null.

However, if I do:
 EntityManagerFactory emf = Persistence.createEntityManagerFactory("unitName");
em = emf.createEntityManager();
Where unitName is the persistence unit defined in my persistence.xml file - I get an entityManager instance. But I want it all handled by JBoss.

This is my setup:

I have a java web service that calls my Stateless Session bean. In my session bean, I try to inject the PersistenceContext, so I can utilize my Entity Beans.

I have a .ear archive - with a .war (that contains my web service) and a .jar that contains my beans (entity and session).

I have everything annotated according to the documentation and nothing special in my persistence.xml file, besides the <jta-data-source>. All of the documentation says that it should work.

I wrote a client that calls the web service (Axis 1.3 client generated). It calls the service fine, but I get a NullPointerException when it tries to call the em.persist() method inside my stateless session bean.

Any ideas? If I need to provide more information I can.

Thanks,

Bryan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2007
Added on Apr 18 2007
13 comments
1,228 views