2.4. Specify a @GeneratedType for the Id

The @Id property should be automated populated by the database, rather than by Java code. What this means that a @GeneratedValue should be specified.

Note

This restriction may be lifted in future versions of JPA Objects.

For example:

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.nakedobjects.applib.annotation.Hidden;
...

public class Customer {

    // {{ Id
    private Long id;
    @Hidden
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    // }}

    ...
}

Because the Id key is automatically generated it generally has no meaning to the end-user, and therefore should also be annotated as @Hidden. This isn't a requirement of JPA Objects, however.

The value of the @GeneratedValue's strategy is a GenerationType:

To capture the ID for use within the domain object, see Section 8.2, “Lifecycle Listeners”.