This content has been marked as final.
Show 3 replies
-
1. Re: Multiple Databases with Identical Schemas
eekboom Mar 30, 2006 2:08 AM (in response to jameswoodward)Hah - if I understand your problem correctly this is exactly what caused a lot of trial-and-error for me.
After all the only thing I had to do is get my entity manager dynamically rather than having it injected:public EntityManager getEntityManager(String unit) { String path = "java:/EntityManager/" + unit; EntityManager entityManager = null; try { InitialContext context = new InitialContext(); try { entityManager = (EntityManager) context.lookup(path); } finally { context.close(); } } catch(NamingException e) { LOGGER.log(Level.WARNING, "Cannot retrieve entity manager: " + entityManager, e); } return entityManager; }
where the "unit" parameter is the name of one of the units in your persistence.xmls.
The entity beans don't need any special coding.
This thread discussed the problem a while ago, but I found it more confusing than helpful:
http://jboss.org/index.html?module=bb&op=viewtopic&t=65869&postdays=0&postorder=asc&start=0
What finally got me going was the answer to my own question here:
http://jboss.org/index.html?module=bb&op=viewtopic&t=79597 -
2. Re: Multiple Databases with Identical Schemas
jameswoodward Mar 30, 2006 3:48 AM (in response to jameswoodward)Many Thanks!
-
3. Re: Multiple Databases with Identical Schemas
epbernard Mar 30, 2006 12:25 PM (in response to jameswoodward)Actually you cna use @PersistenceContexts or @PersistenceUnits to make this code more portable.