TLD
TLD

Reputation: 8135

Can EntityManager know that it is dead?

My code:

emf = Persistence.createEntityManagerFactory("cassandra_pu");
em = emf.createEntityManager();

I change the persistence.xml dynamically to change to IP address of the cassandra_pu unit. However maybe it is executing too fast thus the old entity manager is returned instead of new one. Is there any way to check whether the created em entity manager good enough to use or not?

Upvotes: 2

Views: 99

Answers (2)

Chris
Chris

Reputation: 21165

Some providers allow it but it's native functionality. Check out Eclipselink's refreshMetadata() to pick up changes. But you should be using a new PU if only the database connection/schema is different. Just specify an ORM.xml to override table and scheme names as needed and you can reuse classes

Upvotes: 0

Óscar López
Óscar López

Reputation: 236124

It might depend on the EJB container in use, but in general changes to persistence.xml won't be reflected until the next redeploy of the application - so the "old" entity manager will be returned over and over again until you redeploy.

Upvotes: 1

Related Questions