Upgrade
Sign In : Sign Up : Blog : Search: Language : Help :
Java Persistence Performance

Slow factory.createEntityManager() with EcliseLink

by sirmad posted Aug 7 2015, 5:04

Hello

i make my first steps into the land of JPA and EcliseLink
I wrote a small test programm to fill a h2db database with 100 mio records to test query times.

My problem is, that when i am restarting my test programm the startup takes 30 minutes!

The line where my programm hangs is:
private static EntityManager em = factory.createEntityManager();

It seems so that this line triggers a complete read of all 100 mio entries in my DB?!

But why? And how do i avoid it?

persistence XML is:
http://www.forumslibre.com/forum?attachment=354385&key=-96696355579816378&name=persistence+-+Kopie.xml


by jamesssss posted Aug 10 2015, 7:47
My guess is this is because you are using the H2 database.

H2 is an in-memory database, not a real persistent database. When it starts up H2 reads in the entire database into memory. Try using a real database instead, such as Derby, Postgres, MySQL, Oracle, etc.

You can use a Java profiler to confirm this, such as VisualVM that comes with Java (in bin dir).

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 478, today: 1, week: 3, month: 22

by sirmad posted Aug 11 2015, 2:23
i made another test without eclipselink with pure jdbc
1. connect to db
2. count all lines of my table

-> the programm runs under 1 Second.
so the h2db is not to blame

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 465, today: 0, week: 1, month: 18

by jamesssss posted Aug 11 2015, 8:35
createEntityManager() will load the persistence meta-data and connection to the database. Nothing that should take very long. How big is your persistence unit?

Profiling it would be the best way to find out what is occurring.

Check if you have any events that run on startup.

Try a new persistence unit with no classes to narrow down the cause.

Enable logging on finest to get a trace of what is occurring.

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 530, today: 0, week: 0, month: 19

Id: 354387
Tags: eclipselink, jpa, h2db
Posted: Aug 7 2015, 5:04
Replies: 3
Views: 500, today: 1, week: 1, month: 25
I'm sure
Flag graphic as offensive, or in violation of site rules