Home
Customer entity
Example | -6 shows an extract of the Customer class.
Example 12-6 Customer entity
import ......;
@Entitypublic class Customer implements Serializable {@Idprivate String ssn;
private String title;
@Column(name="FIRST_NAME")private String firstName;
@Column(name="LAST_NAME")private String lastName;
@ManyToMany(mappedBy="customerCollection")private Set<Account> accountCollection;
......// constructor, getter, setter methods
The @Entity annotation defined the class as an entity.
The @Id annotation defines ssn as the primary key.
The @Column annotation maps the fields to a table column if the names do not match. Note that by convention, columns names with underscores (FIRST_NAME) create nice Java field names (firstName).
The @ManyToMany annotation defines the m:m relationship with Account. The mapping is defined in the Account entity.
ibm.com/redbooks