通过注解使用 Hibernate UUIDGenerator [英] Using Hibernate UUIDGenerator via annotations

查看:36
本文介绍了通过注解使用 Hibernate UUIDGenerator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用我的 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")
...

参见 5.1.2.2.1.各种额外的生成器.

这篇关于通过注解使用 Hibernate UUIDGenerator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆