tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jazon <reme...@gmail.com>
Subject Re: Obtaining EntityManager programatically for test purposes
Date Thu, 05 Feb 2009 15:12:39 GMT
anybody know this?
I also need to get entityManager using JNDI.


On Tue, Feb 3, 2009 at 7:56 AM, <Thomas.TH.Hamacher@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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message