users@glassfish.java.net

Re: @PersistenceContext ignored in library jar classes?

From: <forums_at_java.net>
Date: Wed, 18 Sep 2013 05:22:38 -0500 (CDT)

I've just solved the same problem. All was fine in my EAR application until I
cleaned up the architecture and separated the CRUD services into a separate
jar to the Entities and persistence unit. I followed Piotr Norwicki in
http://piotrnowicki.com/2012/11/types-of-entitymanagers-application-managed-entitymanager/
and created my EntityManager via EntityManagerFactory: import
javax.ejb.Stateless; import javax.enterprise.context.RequestScoped; import
javax.enterprise.inject.Disposes; import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager; import
javax.persistence.EntityManagerFactory; import
javax.persistence.PersistenceUnit; @Stateless public class EntityProducer {
@PersistenceUnit(name = "esa2-pu") EntityManagerFactory emf; @Produces
@RequestScoped public EntityManager createEntityManager() { return
emf.createEntityManager(); } public void destroyEntityManager(@Disposes
EntityManager em) { if (em.isOpen()) { em.close(); } } } I needed to add the
@Stateless where Piotr doesn't have it. I'm not sure why and still trying to
work that out.

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