Java Reference
In-Depth Information
The very simple hibernate.cfg.xml file shown in Listing 9-34 serves only to tell Hibernate where to
look for classes that are annotated as entities.
Finally you can configure HibernateItemWriter . It's probably the easiest ItemWriter to configure
given that other components and the Hibernate framework do all the work. HibernateItemWriter
requires a single dependency and has one optional dependency. The required dependency is a reference
to the SessionFactory you configured previously in Listing 9-31. The optional dependency (which you
aren't using in this case) is a reference to a HibernateOperations implementation via the property
hibernateTemplate . 3 Listing 9-35 show the configuration of the job complete with the new
HibernateItemWriter configuration.
Listing 9-35. formatJob .xml Using Hibernate
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns=" http://www.springframework.org/schema/batch"
xmlns:beans=" http://www.springframework.org/schema/beans"
xmlns:util=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<beans:import resource="../launch-context.xml"/>
<beans:bean id="customerFile"
class="org.springframework.core.io.FileSystemResource" scope="step">
<beans:constructor-arg value="#{jobParameters[customerFile]}"/>
</beans:bean>
<beans:bean id="customerFileReader"
class="org.springframework.batch.item.file.FlatFileItemReader">
<beans:property name="resource" ref="customerFile"/>
<beans:property name="lineMapper">
<beans:bean
class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<beans:property name="lineTokenizer">
<beans:bean class="org.springframework.batch.item.file.transform.
DelimitedLineTokenizer">
<beans:property name="names"
value="firstName,middleInitial,lastName,address,city,state,zip"/>
<beans:property name="delimiter" value=","/>
</beans:bean>
</beans:property>
<beans:property name="fieldSetMapper">
<beans:bean class="org.springframework.batch.item.file.mapping.
BeanWrapperFieldSetMapper">
3 This option is rarely used. Typically it's used for testing purposes only.
Search WWH ::




Custom Search