Java Reference
In-Depth Information
Listing 7-46. hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
" http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping class="com.apress.springbatch.chapter7.Customer"/>
</session-factory>
</hibernate-configuration>
Last but not least, you need to actually configure the
org.springframework.batch.item.database.HibernateCusorItemReader . Probably the simplest piece of
the puzzle, this ItemReader implementation requires only two dependencies: a Hibernate
SessionFactory and the HQL string to be executed. Listing 7-47 shows the configuration of the
HibernateCusorItemReader with those two dependencies included as well as injecting query parameters
the same way you did in the JdbcPagingItemReader earlier in this chapter.
Listing 7-47. Configuring the HibernateCursorItemReader
<beans:bean id="customerItemReader"
class="org.springframework.batch.item.database.HibernateCursorItemReader"
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:bean>
In this example, you used an HQL query as your method of querying the database. There are two
other ways to specify the query to execute. Table 7-3 covers all three options.
 
Search WWH ::




Custom Search