This content has been marked as final.
Show 4 replies
-
1. Re: BMT does not work the expected way.
waynebaylor Jul 26, 2007 3:03 PM (in response to sumantkb)From the EJB3 Persistence spec (section 5.3, page 116) it says to use:
EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("Order"); EntityManager em = emf.createEntityManager();
when working in a Java SE environment.
When working in an EE container use injection/JNDI lookup. For example:@Stateless @TransactionManagement(TransactionManagementType.BEAN) public class TravelAgentBean { @PersistenceUnit(unitName="titan") private static EntityManagerFactory factory; ...}
ps. you can get a UserTransaction with: @Resource UserTransaction tx; if you want to avoid the jndi lookup. -
2. Re: BMT does not work the expected way.
sumantkb Jul 30, 2007 3:09 AM (in response to sumantkb)Hi
Thanks for the response.
Please look at 5.1 , second last paragraph. It says
"Both container-managed entity managers and application-managed entity managers and their persistence contexts are required to be supported in Java EE web containers and EJB containers. "
Would not that imply that the EntityManagerFactory factory = Persistence
.createEntityManagerFactory("titan"); should work as well? -
3. Re: BMT does not work the expected way.
waynebaylor Jul 30, 2007 9:22 AM (in response to sumantkb)"Technically" it just needs to support the EntityManager, not the method of retrieving it.
-
4. Re: BMT does not work the expected way.
wolfc Jul 30, 2007 10:14 AM (in response to sumantkb)From the same paragraph:
In less common use cases within Java EE environments, applications may need to access a persistence context that is ?stand-alone??i.e. not propagated along with the JTA transaction across the EntityManager references for the given persistence unit.
Never tried it like you have, but committing your JTA transaction doesn't make much sense.
Try em.joinTransaction() or em.getTransaction().commit().
Lets see what happens.