11

JPA: lazy loading for lazy developers, the performance issue

 3 years ago
source link: https://marco.dev/2009/03/09/jpa-performance-inser/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

java-version.com: What's new in Java 16? 15? Keep up to date!

JPA: lazy loading for lazy developers, the performance issue

I found and interesting article about loading and reading data with JPA. There are performance issues when you want to insert 1’000 or 10’000 records in the database.

Before ORM life was complicated … 25 lines of code to insert a line in the database, not it’s easier: entityManager.persist(object)!

The frameworks (Hibernate, Toplink …) do all the work and they do very well the work. The problem with JPA is that we cannot flush the session like in hibernate and send 50 or 100 records in a block to the DB. JPA send and retrieve each object in a transaction. Inserting 10’000 records takes minutes … 1’000’000 hours.

The solution is to use direcly JDBC, ETL product or frameworks (Spring Batch, …).

JPA is something great but it cannot manage everything 🙁 no party for the lazy developers … yet!

Author

Marco Molteni

Marco Molteni Blog


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK