Java Reference
In-Depth Information
With the Hibernate framework added to your project, you can map your Customer object to the
Customer table in the database. To keep things simple, you will use Hibernate's annotations to configure
the mapping. Listing 7-44 shows the updated Customer object mapped to the Customer table.
Listing 7-44. Customer Object Mapped to the Customer Table via Hibernate Annotations
package com.apress.springbatch.chapter7;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
public class Customer {
@Id private long id;
private String firstName;
private String middleInitial;
private String lastName;
private String address;
private String city;
private String state;
private String zip;
List<Transaction> transactions;
// Accessors go here
public String toString() {
StringBuilder output = new StringBuilder();
output.append(firstName + " " +
middleInitial + ". " +
lastName + "\n");
output.append(address + "\n");
output.append(city + ", " + state + "\n");
return output.toString();
The Customer class's mapping consists of identifying the object as an Entity using the JPA annotation
@Entity , specifying the table the entity maps to using the @Tab le annotation, and finally identifying the
ID for the table with the @Id tag. All other attributes on the Customer will be mapped automatically by
Search WWH ::

Custom Search