This content has been marked as final.
Show 6 replies
-
1. Re: EJB2 interop, how to obtain EntityManager
triathlon98 Jul 12, 2005 2:22 AM (in response to triathlon98)ok, if you search long enough, you will find the answer, I think I cracked it by using the following code :
public EntityManager getEntityManager( String unit ) { try { InitialContext jndi = new InitialContext(); Object obj = jndi.lookup( "java:managedEntityFactory." + unit ); jndi.close(); return ( (ManagedEntityManagerFactory) obj ).getSession(); } catch (Exception e) { throw new EJBException( "Can't find EntityManager", e ); } }
-
2. Re: EJB2 interop, how to obtain EntityManager
donniedarko Jul 12, 2005 6:20 AM (in response to triathlon98)Thank you.
This actually solved my issue with selecting entity managers on the fly described here:
http://www.jboss.org/index.html?module=bb&op=viewtopic&t=65869
I will reference to your solution from that thread. -
3. Re: EJB2 interop, how to obtain EntityManager
bill.burke Jul 12, 2005 10:46 AM (in response to triathlon98)EJB 3 Beta1 should support EJB 2.1 style beans.
-
4. Re: EJB2 interop, how to obtain EntityManager
triathlon98 Jul 12, 2005 1:25 PM (in response to triathlon98)Bill,
Could you point me in the direction of a manual/article/example which shows how to do that. Don't seem to have found many derails about this yet.
Thanks,
Joachim -
5. Re: EJB2 interop, how to obtain EntityManager
dgreen999 Sep 8, 2005 12:47 PM (in response to triathlon98)I'm also interested in seeing some documentation on this topic. Any pointers?
Another issue: is there a way to do this without directly accessing the JBoss APIs? -
6. Re: EJB2 interop, how to obtain EntityManager
dgreen999 Sep 8, 2005 4:10 PM (in response to triathlon98)The following appears to work on JBoss 4.0.3RC2
/** * @param managerName the name of the EntityManager as specified in the persistence.xml */ public EntityManager getEntityManager(String managerName) throws javax.naming.NamingException { // TODO: the following code is JBoss-specific. EntityManager entityManager; InitialContext jndi = new InitialContext(); try { entityManager = (EntityManager) jndi.lookup("java:/EntityManagers/"+managerName); } finally { jndi.close(); } return entityManager; }
The returned entityManager is the same as if it were created via annotations and injection (ie: it's an instance of InjectedEntityManager). The nice thing here is that even though the technique is JBoss-specific, it doesn't use any org.jboss.* packages.