Primary Keys
  • All entities must declare a primary key/identifier
  • Primary keys should be of the following types: any Java primitive type, any primitive wrapper type; java.lang.String; java.util.Date; java.sql.Date
  • Do not use floating-point types!
Primary Key Example  
  @Entity
  public class EntityClass {
    private Long id;

    @Id
    public Long getId() {
      return id; // Application-manged key!
    }
  }
  • A primary key may be generated by the persistence provider
Auto-Generated Key Example  
  • The persistence provider may use a table/sequence to generate keys
Table-Generated Key Example