Java Reference
In-Depth Information
2. Configure EntityManagerFactory and the JPA Transaction Manager.
EntityManagerFactory is the source of an EntityManager for the job. It along
with a JPA-supported transaction manager is required.
3. Map the Customer class. You use annotations to configure the mapping of the
Customer class to the Customer table.
4. Configure the JpaItemWriter . The last step is to configure the new ItemWriter
to save the items read in the job.
Let's start with the persistence.xml file, which is shown in Listing 9-36. This file needs to live in the
<PROJECT_HOME>/src/main/resources/META-INF/ directory with the name persistence.xml per the JPA
Listing 9-36. persistence.xml
<persistence xmlns=""
<persistence-unit name="customer" transaction-type="RESOURCE_LOCAL">
The persistence.xml file required for this example is about as simple as you can create. The
persistence unit is named customer with the application controlling the transactions. You have a single
class mapped with annotations, the Customer class. To get started with JPA, that is really all you need for
a persistence.xml file.
Next you can update the launch-context.xml file with an EntityManagerFactory and Spring's
JpaTransactionManager . Listing 9-37 shows the additions you need to make to a base launch-context.xml
file to incorporate the JPA components.
Listing 9-37. Launch-context.xml Updates for JPA
<bean id="entityManagerFactory"
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="customer" />
<property name="jpaVendorAdapter">
<property name="showSql" value="true" />
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
Search WWH ::

Custom Search