Java Reference
In-Depth Information
Hibernate is stateful. If you are reading a million items, processing them, then writing those same
million items, the Hibernate session will cache the items as they are read and an
OutOfMemoryException will occur.
Another issue with using Hibernate as a persistence framework for batch processing is that
Hibernate incurs larger overhead than straight JDBC does. When processing millions of records, every
millisecond can make a big difference 3 .
I'm not trying to persuade you from against using Hibernate for your batch processing. In
environments where you have the Hibernate objects mapped previously for another system, it can be a
great way to get things up and running. Also, Hibernate does solve the fundamental issue of mapping
objects to database tables in a very robust way. It's up to you and your requirements to determine if
Hibernate or any ORM tool is right for your job.
Cursor processing with Hibernate
To use Hibernate with a cursor, you will need to configure the sessionFactory, your Customer mapping,
the HibernateCursorItemReader, and add the Hibernate dependencies to your pom.xml file. Let's start
with updating your pom.xml file.
Using Hibernate in your job will require three additional dependencies to be added to your POM.
Listing 7-43 shows the addition of the hibernate-core, hibernate-entity manager, and the hibernate-
annotations to pom.xml .
Listing 7-43. Hibernate Dependencies in POM
3 A one millisecond increase per item over the course of a million items can add over 15 minutes of
processing time to a single step.
Search WWH ::

Custom Search