My goal is to create an entity Device that has a unique field IMEI and I would like to use it as a primary key, and specify it at device registration time (manually specifie
A straightforward solution could be to use the @PrePersist annotation on your entity class.
Simply add the method
@PrePersist
private void ensureId(){
this.setId(UUID.randomUUID().toString());
}
and get rid of the @GeneratedValue annotation.
PrePersist documentation: http://docs.oracle.com/javaee/5/api/javax/persistence/PrePersist.html
Stefano