UUID with Play Framework

I would like to use the UUID instead of the regular identifier of my models.

Can this be done using the playback platform?

+5
source share
2 answers

First, do not project (play.db.jpa.Model) the model in the Model that you want to generate Id, but use the GenericModel.

then you can use a helper class that is called when the object is created (in the constructor).

or call a helper class when saving (so I have to create a DAO wrapper, the saving process is done in the DAO wrapper not in the object so that I can generate id while saving the object)

or if you want a simpler approach, use JPA UUID. See code below.

@Entity
public class User extends GenericModel {
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    public String id;
}
+6

, Model GenericModel, , , Long @Id .

, GenericModel @Id. String UUID. .

, JPA UUID. , UUID , , .

+5

All Articles