我用我的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