JBoss Community

jboss7 quickstarts entitymanager injection question

created by robert walker in JBoss AS7 Development - View the full discussion

Hi all, I am looking at the examples in jboss7 quickstarts , login and kithensink (ones that hit a DB)

and wondering how jb7 knows which persistence unit to inject.

 

for example

 

if standalone.xml defines a few datasources  (like the default)

 

.....

 

 

and say another named  "MyDataDSource"

 

 

....

 

 

how does jboss know which one to inject when executing code like this from login quickstart's   ManagedBeanUserManager.java file

 

@Inject

private EntityManager userDatabase;

 

 

No designation which PU to to inject,  I was thinking there would have to be code along the idea of the snippet below

 

@PersistenceContext(unitName = "MyDataDSource")

EntityManager em;

 

 

I did read the "Chapter 5. CDI + JPA + EJB + JTA + JSF: Login quickstart" but was eagerly wanting to know how jboss knows which

one to inject but didn't see it, which means it's so obvious that it does not need to be stated. So I realize i should know it this

but I don''t. :-(

 

I see the the pattern suggested by CDI is resource producers, but

Resources.java has

 

   // Expose an entity manager using the resource producer pattern

 

   @SuppressWarnings("unused")

 

   @PersistenceContext

 

   @Produces

 

   private EntityManager em;

 

with no designation either

 

can someone point me to a reesource to explain this a bit more

 

thanks

Reply to this message by going to Community

Start a new discussion in JBoss AS7 Development at Community