JPA - Performance with using multiple entity manager

Posted by Nguyen Tuan Linh on Stack Overflow See other posts from Stack Overflow or by Nguyen Tuan Linh
Published on 2012-09-21T09:28:51Z Indexed on 2012/09/21 9:37 UTC
Read the original article Hit count: 352

Filed under:
|
|
|
|

My situation is:

  • The code is not mine
  • I have two kinds of database: one is Dad, one is Son.
  • In Dad, I have a table to store JNDI name. I will look up Dad using JNDI, create entity manager, and retrieve this table.
  • From these retrieved JNDI names, I will create multiple entity managers using multiple Son databases.

The problem is:

  • Son have thousands of entities. It takes each Son database around 10 minutes to load all entities. If there is 4 Son databases, it will be 40 minutes.

My question:

  • Is there any way to load all entities and use them for all entity manager?

Please look at the code below
For each Son JNDI:

Map<String, String> puSonProperties = new HashMap<String, String>();
puSonProperties.put("javax.persistence.jtaDataSource", sonJndi);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("PUSon", puSonProperties);

PUSon - All of them use the same persistence unit

log.info("Verify entity manager for son: {0} - {1}", sonCode, 
         emSon.find(Son_configuration.class, 0) != null ? "ok" : "failed!");

This is the actual code where the loading of all entities begins. 10 mins.

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa