通过注解使用 Hibernate UUIDGenerator [英] Using Hibernate UUIDGenerator via annotations
问题描述
我使用我的 uuid 如下:
I'm using my uuid as following:
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
private String uuid;
但我收到了一个智能的休眠警告:
but I'm getting a smart Hibernate warning:
使用org.hibernate.id.UUIDHexGenerator不生成 IETF RFC 4122合规的 UUID 值;考虑使用org.hibernate.id.UUIDGenerator 代替
Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values; consider using org.hibernate.id.UUIDGenerator instead
所以我想切换到 org.hibernate.id.UUIDGenerator
,现在我的问题是我应该如何将它告诉 Hibernate 的生成器.我看到有人将它用作hibernate-uuid" - 所以这是我尝试过的,但结果是负面的:
So I want to switch to org.hibernate.id.UUIDGenerator
, now my question is how should I tell it to Hibernate's generator. I saw some guy used it as a "hibernate-uuid" - so this is what I've tried, but with negative result:
@Id
@GeneratedValue(generator = "hibernate-uuid")
@GenericGenerator(name = "hibernate-uuid", strategy = "hibernate-uuid")
@Column(name = "uuid", unique = true)
private String uuid;
推荐答案
应该是uuid2
:
...
@GenericGenerator(name = "uuid", strategy = "uuid2")
...
这篇关于通过注解使用 Hibernate UUIDGenerator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!