I have one persistence unit configured in my persistence.xml, but I have two databases. These databases are identical in terms of schema. I am trying to do the following:
Persistence.createEntityManagerFactory("unit", primaryProperties);
Persistence.createEntityManagerFactory("unit", secondaryProperties);
The properties contain different connection settings (user, password, jdbc url, ...).
I actually tried this, and it seems that hibernate (my jpa provider) returns the same instance in the second call, without worrying about properties.
Do I need to copy the configuration to the second block?
I nailed it to something other than I thought before. EntityManagers (and factories) returned by the above calls work as expected, but problem getDelegate(). I need the base session to support legacy code in my application, which directly depends on the hibernate api. I have done this:
final Session session = (Session) manager.getDelegate();
But somehow I get a session working in the primary database even when using the entitymanager that works with the second.
source
share