Java Reference
In-Depth Information
Primary Key Generation Strategy Description
Indicates that a database sequence should be used to
generate the entity's primary key value.
Indicates that a database table should be used to
generate the entity's primary key value.
In most cases, the GenerationType.AUTO strategy works properly, therefore it is
almost always used, for this reason the New Entity Class wizard uses this strategy.
When using the sequence or table generation strategies, we might have to
indicate the sequence or table used to generate the primary keys. These can
be specified by using the @SequenceGenerator and @TableGenerator
annotations, respectively. Consult the Java EE 6 JavaDoc at http:// for details.
Adding persistent fields to our entity
At this point, our JPA entity contains a single field, its primary key, admittedly not
very useful. We need to add a few fields to be persisted to the database.
package com.ensode.jpaweb;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
public Long getId() {
return id;
public void setId(Long id) { = id;
public String getFirstName() {
Search WWH ::

Custom Search