1

I have an uncommon requirement in my web application. It is a normal tomcat, spring, hibernate application, but each user want to select the DB to work with directly after login. After a successful login the user get a drop down list with available Databases, selects one and continue using the application. All Databases have the same schema, only different data and the connection data are stored in a properties file.

I think i have to create an EntityManager for each user after login. I am wondering, what is the best practice to do so. May be it also makes sense, that when two users selects the same DB, that they share the EntityManager (e.g. A check whether an EntityManager for this DB already exists before creating a new one). I also want to use connection-pooling per EntityManager

Concrete questions

  1. Is there a best practice?
  2. Which EntityManagerFactory (see below) is suitable, the container-based or the standalone-one?
  3. Is there any risks, like memory leakage, performance etc.?

So far I checked the following classes from spring:

  • LocalEntityManagerFactoryBean
  • LocalContainerEntityManagerFactoryBean

This is also a link that creates EntityManager programatically but with spring classes https://vladmihalcea.com/how-to-bootstrap-jpa-programmatically-without-the-persistence-xml-configuration-file/

Rasha Elsayed
  • 660
  • 1
  • 7
  • 22

0 Answers0