Warm tip: This article is reproduced from stackoverflow.com, please click
playframework uuid

UUID with the Play Framework

发布于 2020-04-23 11:21:28

I'd like to use UUID instead of the regular id on my models.

Can this be done with the play framework?

Questioner
fulmicoton
Viewed
14
indrap 2011-09-14 16:49

First don`t extend (play.db.jpa.Model) Model in the Model you want to generate the Id but use GenericModel.

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

or call the helper class when saved(thus i have to create wrapper DAO, the save process is done in wrapper DAO not in the Object so that i could generate id the save the object)

or if you want more simple 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;
}