An entity class is used to represent a table in a database, and the fields in an entity class correspond to columns in that table. In an entity class, you can use annotations to specify how fields in an entity class are mapped to the corresponding database columns and tables.
For example, the following @Column annotation marking the field address maps the field to the column named CUSTOMER_ADDRESS in the database table.
@Column(name = "CUSTOMER_ADDRESS") private String address;
The following annotations are commonly used when mapping entity classes.
Annotation | Description |
---|---|
@Id | This annotation specifies the primary key property or field of an entity. |
@GeneratedValue | This annotation is used in conjunction with @Id, and allows you to specify the strategy used to automatically generate the values of primary keys. |
@Column | This annotation is used to specify a mapped column for a persistent property or field. |
@ManyToMany | This annotation defines a many-valued association with many-to-many multiplicity. |
@ManyToOne | This annotation defines a single-valued association to another entity class that has many-to-one multiplicity. |
@OneToMany | This annotation defines a many-valued association with one-to-many multiplicity. |
For more on using annotations and annotation elements to map entities in an enterprise application, see the Java EE 5 Tutorial:
For more on the specifications on annotations and annotation elements, see the Java EE 5 API specifications for javax.persistence: