Java Reference
In-Depth Information
<bean id="transactionManager"
<property name="entityManagerFactory" ref="entityManagerFactory" />
You begin looking at the configuration for launch-context.xml with the EntityManagerFactory .
Configuring Spring's org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean requires
four dependencies:
A datasource: The EntityManager uses this to connect to the database.
A persistence unit name :This defines the group of persistable classes for the
EntityManager .
jpaVendorAdapter : JPA is just a specification like JDBC or JavaServer Faces (JSF).
Someone needs to implement the specification in order for you to use it. In this
example, you're using Hibernate's implementation of JPA.
jpaDialect : This gives you a vendor-dependent way of handling things that JPA
doesn't provide for (accessing the underlying database connection, for example).
Next, you configure Spring's org.springframework.orm.jpa.JpaTransactionManager with its single
dependency, the EntityManagerFactory you just configured.
The next piece of the JPA puzzle is mapping the Customer object to the Customer table. You use
annotations for this as you have in the past. The nice thing about the way you mapped the Customer class
previously is that you used all JPA annotations for the Hibernate example. This allows you to reuse the
Customer object unchanged for JPA. Listing 9-38 shows the Customer class mapped using the JPA
Listing 9-38. Mapped with JPA Annotations
package com.apress.springbatch.chapter9;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String firstName;
private String middleInitial;
private String lastName;
Search WWH ::

Custom Search