in my Java web application, I would like to persist every 100 instances of the save entity at once, what is the best way to do that? I have some time constraints that I have to respect, the persisting operation should be fast. I there any method faster than the others? Thank you
save(employee); } tx. commit(); session. close(); By default, Hibernate will cache all the persisted objects in the session-level cache and ultimately your application would fall over with an OutOfMemoryException somewhere around the 50,000th row.
Hibernate provides the facility to persist the collections. A collection can be a list, set, map, collection, sorted set, sorted map. java.
Basically what you are looking for is batch insert into database using JPA. These topics have already been brought up, these will help you:
Using Hibernate's batch inserts. Hiberate provides methods for batch inserting and updating entities.
Disabling automatic ID generation. If you generate ids automatically, Hibernate executes query for each entity to generate the primary key.
Basically I think that disabling automatic ID generation is a bad idea. You can take most of Hibernate's batch methods, but this will not save you much of performance.
After this is done, I suggest you looking for optimizations in other layers of your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With