Stefan Strooves
Stefan Strooves

Reputation: 634

Improve JPA initialization performance

I use the JPA with Eclipselink and Derby DB. I wonder if there is an option to improve the performance when initiating the process since the following code is invoked.

factory = Persistence.createEntityManagerFactory(persistenceUnitName);

There is delay and the process is invoked and writing status in the console.

Is there a way to omit that process and improve the performance?

Upvotes: 1

Views: 230

Answers (1)

James
James

Reputation: 18379

Creating an EntityManagerFactory requires the persistence unit to be deployed. This is something you should only ever do once for the life of your application or server.

Since it is only done once, the performance should not be a major issue, unless you have architected your application poorly and are calling it multiple times.

Ways to improve the performance include:

  • Use static weaving, this moves the weaving processing to your build code and removes it from the startup time.
  • List your classes in your persistence.xml and use <exclude-unlisted-classes>true</exclude-unlisted-classes>, this avoids having to search the entire jar classpath.
  • Ensure you are not validating the orm.xml schema, this can be expensive.

Upvotes: 1

Related Questions