Java Reference
In-Depth Information
provides a batching functionality similar to
JdbcBatchItemWriter
's implementation without dealing
directly with the SQL.
Configuring
HibernateItemWriter
is simple. All but the configuration of the actual ItemWriter
should be familiar, because it's the same as the configuration and coding you did for the Hibernate-
supported ItemReaders. To modify
formatJob
to use Hibernate, you need to update the following:
•
The pompom:
The POM needs to incorporate the Hibernate dependencies.
Customer.java
: You use annotations to configure the mapping for the
Customer
object, so you need to add those to the
Customer
class.
•
•
SessionFactory
: You need to configure both the
SessionFactory
and a new
TransactionManager
to support Hibernate.
•
HibernateItemWriter
: You can configure the new ItemWriter using
HibernateItemWriter
.
Let's start with the POM updates. For Hibernate to work with Spring Batch, you need to include the
Hibernate dependencies as well as Spring's ORM-supporting dependencies. Listing 9-31 shows the
additions you need to make to the POM.
Listing 9-31.
Pom Additions for Supporting Hibernate
…
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.0.SP1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<optional>true</optional>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<optional>true</optional>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.framework.version}</version>
</dependency>
…