Java Reference
In-Depth Information
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.
JobRepositoryFactoryBean">
<property name="isolationLevelForCreate" value="ISOLATION_DEFAULT" />
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="placeholderProperties"
class="org.springframework.beans.factory.config.
PropertyPlaceholderConfigurer">
<property name="location" value="classpath:batch.properties" />
<property name="systemPropertiesModeName"
value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="1" />
</bean>
</beans>
The transactionManager relationship to the entityManagerFactoryBean is the same as Hibernate's
relationship between the HibernateTransactionManager and the SessionFactory. For the EntityManager
configuration, you specify a datasource like you did in Hibernate; however, since the JPA spec defines
where to look for the persistence.xml file (in the META-INF directory), you don't need to configure that.
You do need to tell your EntityManager the persistence unit name and configure the vendor
implementation. Since Hibernate implements the JPA spec, you will use it for this example.
The last piece of the JPA puzzle is to configure your ItemReader. As mentioned, JPA does not
support cursor database access but it does support paging database access. The ItemReader will be the
org.springframework.batch.item.database.JpaPagingItemReader which uses three dependencies: the
entityManager you configured in the launch-context.xml , a query to execute, and in your case, your
query has a parameter, so you will inject the value of the parameter as well. Listing 7-51 shows the
customerItemReader configured for JPA database access.
Listing 7-51. customerItemReader with JPA
<beans:bean id="customerItemReader"
class="org.springframework.batch.item.database.JpaPagingItemReader"
scope="step">
<beans:property name="entityManagerFactory" ref="entityManagerFactory" />
<beans:property name="queryString"
value="select c from Customer c where c.city = :city" />
<beans:property name="parameterValues">
<beans:map>
<beans:entry key="city" value="#{jobParameters[city]}"/>
</beans:map>
</beans:property>
</beans:bean>
Executing the job as it currently is configured will output a file containing all of the customers'
names and addresses within the city specified at the command line. There's another way to specify
 
Search WWH ::




Custom Search