I have one persistence unit configured in my persistence.xml but i have two databases. Those databases are identical, regarding the schema. What i am trying to do is:
Persistence.createEntityManagerFactory("unit", primaryProperties);
Persistence.createEntityManagerFactory("unit", secondaryProperties);
The properties contain different connection settings (user, password, jdbc url, ...).
I tried this actually and it seems that hibernate (my jpa provider) returns the same instance in the second call, without taking care of the properties.
Do i need to copy the configuration to a second unit?
I nailed it down to something different than i thought before. The EntityManagers (and Factories) returned by the calls above work as expected, but getDelegate()
seems to be the problem. I need to get the underlying session to support legacy code in my application which relies directly on the hibernate api. What i did is:
final Session session = (Session) manager.getDelegate();
But somehow i receive a session operating on the primary database even when using an entitymanager which operates on the second.