I have a problem getting my EntityManagers correctly.
I'm using Hibernate for JPA and JTA (Atomikos) but without application server.
This all does work as expected until I tried to send a query to a second database.
I've setup two persistence units with different datasources in JNDI (the setup and log looks good).
But when I create a new entity manager, the database connection always points to the database first queried. Just to mention: I have two EntityManagerFactories (as expected... :)).
Code:
Connection c = ((HibernateEntityManager) em1).getSession().connection();
DatabaseMetaData dmd = c.getMetaData();
System.out.println("*** *** *** EM URL: " + dmd.getURL());
Connection c = ((HibernateEntityManager) em2).getSession().connection();
DatabaseMetaData dmd = c.getMetaData();
System.out.println("*** *** *** EM URL: " + dmd.getURL());
Both urls are the same... Can anybody give me a hint on how to setup hibernate JPA to use two databases correctly? It does look to me like the EntityManagerFactory both work on the same underlying Session.
Thanks for any help.