On Feb 5, 2009, at 7:12 AM, Jazon wrote:
anybody know this?
I also need to get entityManager using JNDI.
Hi Jazon,
If you only have one or two EntityManagers than this is definitely the
recommended approach:
http://www.nabble.com/Re%3A-Obtaining-an-EntityManager-instance-outside-an-EJB-p21701466.html
-David
On Tue, Feb 3, 2009 at 7:56 AM, <thomas.th.hamac...@partner.bmw.ch>
wrote:
Hi @all,
as a lot of folks I am not really satisfied with how JBoss
currently cares
about their embedded application server.
So I finally decided not to struggle around anymore, but to move to
openEJB
as this seems a lot smoother and people speak very good about it.
So far everything works fine with openEJB, the only point I have is
to
obtain an EntityManager programatically and not through dependency
injection
for test purposes.
I am trying to migrate the following function, which worked on JBoss:
------------------------------------
public EntityManager getEntityManager(String persistenceUnitName)
throws
ResourceNotFoundException {
LOG.info("getEntityManager " + persistenceUnitName);
EntityManager em = null;
String lookupString = "java:/EntityManagers/" +
persistenceUnitName;
try {
LOG.trace(String.format("Looking for EntityManager at %s",
lookupString));
em = (EntityManager) lookup(lookupString);
} catch (NamingException ex) {
LOG.error(String.format("An error occured while looking for
EntityManager at %s", lookupString), ex);
throw new ResourceNotFoundException("An error occured while
looking
for EntityManager at %s", lookupString);
}
LOG.trace(String.format("Returning EntityManager %s", em));
return em;
}
------------------------------------
So as you can see, I could lookup different entityManagers by their
persistenceUnitName through JNDI.
Is there anything similar, how this can be done using openEJB?
I saw solutions how the entityManager is obtained through a
SessionBean
after it has been deployed and the EM has been injected.
But this can only be a work-around to me, as I see no chance with
handling
different entityManagers with different persistence-units.
Anyone has an idea on this?
Thanks
Thomas