File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Injecting an EntityManager Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Injecting an EntityManager" Watch "Injecting an EntityManager" New topic

Injecting an EntityManager

Khaled Mahmoud
Ranch Hand

Joined: Jul 15, 2006
Posts: 361

When I want to inject an EntityManager, I use the PersistenceContext annotation with the name element that points to the JNDI entry name where the EntityManager is found.

Does this mean that the application deployer must create JNDI entries for the name provided by the annotation before the application starts. And what happens when the unitName is not specified???

Thanks in advance

Life is the biggest school
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
I think the EJB container takes care of creating the JNDI entries as a part of the Enterprise Naming Context for the bean.
Regarding your second query, if the persistent unit name is not specified, I think the default pesistent unit is assumed(which should be the only PU defined for the application). If more than one PU is defined the you get

and then it is mandatory to priovide unit name.

Thanks and Regards
I agree. Here's the link:
subject: Injecting an EntityManager
It's not a secret anymore!