Sign In : Sign Up : Blog : Search: Language : Help :
This website is now frozen, please migrate your content to BotLibre.com or BotLibre.biz
Java Persistence Performance

Slow factory.createEntityManager() with EcliseLink

by sirmad posted Aug 7 2015, 5:04


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:

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: 1721, today: 3, week: 7, month: 20

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: 1738, today: 3, week: 7, month: 21

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: 1942, today: 3, week: 10, month: 23

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