jpa Basic mapping Entity with sequence managed Id


Here we have a class and we want the identity field (userUid) to have its value generated via a SEQUENCE in the database. This SEQUENCE is assumed to be called USER_UID_SEQ, and can be created by a DBA, or can be created by the JPA provider.

public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    @SequenceGenerator(name="USER_UID_GENERATOR", sequenceName="USER_UID_SEQ")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="USER_UID_GENERATOR")
    private Long userUid;

    private String userName;