Here is a challenge that I found at my job: We have a java web application and several databases (one per customer) (The same database/metadata for each customer). Also there is a central database which keeps customers info such Database URL and forth.
At the login screen the user informs Customer ID, Login and Password, hit the login button then first the web application goes to the central database in order to find the Customer database's URL (I have a separate entity manager factory for it), then it goes back and create a new entity manager factory for that customer database. So far so good, I can see customer 1's data.
However when I logout and try to login under a different customer ID (which means a different database) the entity manager factory, which was created before, is still "connected" to the prior customer's database even having the application passing the parameters map containing the new database url.
My question is if there is a way to make JPA to connect to different databases without having to create an entity manager factory for each customer. I know that EntityManagerFactory objects caches all the database metadata so is there a way to change, say, the database url property and refresh the factory?
Thank you,
Gyo