Well it is usually a one to one relationship between a PersistenceUnit/EntityManagerFactory/Database, so when you create an EntityManagerFactory it is immutable, meaning you can't change it once it is created, and this is how it should be. If you want to point to different databases at runtime, you will need a persistence
unit per database, then you might be able to write code that gets an EntityManager from one of the existing persistence units.
Mark