Home
Mapping the table and columns
To specify the mapping of the entity to a database table, we use @Table and @Column annotations (Example | 2-2).
Example 12-2 Entity with mapping to a database table
@Entity@Table (schema="ITSO", name="CUSTOMER")public class Customer implements java.io.Serializable {
@Id@Column (name="SSN")private String ssn;@Column (name="LAST_NAME")private String lastName;private String title;private String firstNname;......
![]()
![]()
The @Table annotation provides information related to which table and schema the entity corresponds to.
![]()
The @Column annotation provides information related to which column is mapped by an entity property. By default, properties are mapped to columns with the same name, and the @Column annotation is used when the property and column names differ.
Note: Entities support two types of persistence mechanisms:
![]()
Field-based persistence-The entity properties must be declared as public or protected and instruct the JPA provider to ignore getter/setters.
![]()
Property-based persistence-You must provide getter/setter methods. We recommend to use the property-based approach (as in Example | 2-2), because it is more adherent to the Java programming guidelines.
ibm.com/redbooks