Java Reference
In-Depth Information
Table 7-3. Hibernate Query Options
Option
Type
Description
queryName
String
This references a named Hibernate query as
configured in your Hibernate configurations.
queryString
String
This is an HQL query specified in your Spring
configuration.
queryProvider
HibernateQueryProvi
der
This provides the ability to programmatically build
your Hibernate Query.
That's all that is required to implement the Hibernate equivalent to JdbcCursorItemReader.
Executing this job will output the same output as your previous job.
Paged Database Access with Hibernate
Hibernate, like JDBC, supports both cursor database access as well as paged database access. The only
change required is to specify the HibernatePagingItemReader instead of the
HibernateCursorItemReader in your copyJob.xml file and specify a page size for your ItemReader. Listing
7-48 shows the updated ItemReader using paged database access with Hibernate.
Listing 7-48. Paging Database Access with Hibernate
<beans:bean id="customerItemReader"
class="org.springframework.batch.item.database.HibernatePagingItemReader"
scope="step">
<beans:property name="sessionFactory" ref="sessionFactory"/>
<beans:property name="queryString"
value="from Customer where city = :city"/>
<beans:property name="parameterValues">
<beans:map>
<beans:entry key="city" value="#{jobParameters[city]}"/>
</beans:map>
</beans:property>
<beans:property name="pageSize" value="10"/>
</beans:bean>
Using Hibernate can speed up development of batch processing in situations where the mapping
already exists as well as simplify the mapping of relational data to domain objects. However, Hibernate
is not the only kid on the ORM block. The Java Persistence API (or JPA for short) is the native Java
implementation of ORM persistence. You'll look at that next.
 
 
Search WWH ::




Custom Search