Java Reference
In-Depth Information
<bean id="jobRepository"
<property name="isolationLevelForCreate" value="ISOLATION_DEFAULT" />
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<bean id="placeholderProperties"
<property name="location" value="" />
<property name="systemPropertiesModeName"
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="1" />
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"
<beans:property name="entityManagerFactory" ref="entityManagerFactory" />
<beans:property name="queryString"
value="select c from Customer c where = :city" />
<beans:property name="parameterValues">
<beans:entry key="city" value="#{jobParameters[city]}"/>
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