Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I say an entity manager injected into session bean must be container managed?

 
Mellon Sun
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For application managed entity manager, a EntityManagerFactory should be injected and get the entity manager via EntityManagerFactory.createEntityManager().
For container managed entity manager, it can be directly injected into a session bean.

So, can I say if an entity manager is injected into a session bean, then it should be a container managed one, and a container managed entity manager should be a JTA entity manager, then an injected entity manager in EJB must be a JTA entity manager but never can be a resource-local one?
 
LakshmiNarayana Kodali
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are correct

If an EntityManager is injected into Session bean using DI, it is Container managed JTA Entity Manager. And Container Managed EntityManager cannot be resouce local EntityManager.


Application Managed EntityManagers can be created using EntitymanagerFactory but cannot be injected using DI.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic