我用我的UUID如下:通過註釋中使用Hibernate UUIDGenerator
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
private String uuid;
,但我得到一個智能休眠警告:
使用 org.hibernate.id.UUIDHexGenerator 這不會生成符合UUID值的IETF RFC 4122 ;考慮使用 org.hibernate.id.UUIDGenerator代替
所以我想切換到org.hibernate.id.UUIDGenerator
,現在我的問題是我應該怎麼告訴它Hibernate的發電機。我看到一些人用它作爲一個「休眠的UUID」 - 所以這是我嘗試過,但陰性結果:
@Id
@GeneratedValue(generator = "hibernate-uuid")
@GenericGenerator(name = "hibernate-uuid", strategy = "hibernate-uuid")
@Column(name = "uuid", unique = true)
private String uuid;
[它是4.1相同(http://docs.jboss.org/hibernate/orm/4.1/manual/en-美國/ html_single /#映射聲明-ID)。另請注意,它使用java.util.UUID.randomUUID()。 – CorayThan 2013-05-01 18:15:31
一個簡單的@Id @GeneratedValue private java.util.UUID id;' 在Hibernate 5+中工作。請參閱[文檔](http://docs.jboss.org/hibernate/orm/5.0/userguide/html_single/Hibernate_User_Guide.html#identifiers)。 – 2016-06-10 09:11:16