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

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

问题描述

我用我的UUID如下:

  @Id
@GeneratedValue(发电机=的「uuid)
@GenericGenerator(名称=的「uuid」,战略=的「uuid)
@Column(名称=的「uuid」,独特= TRUE)
私人字符串UUID;

但我得到一个智能休眠警告:


  

使用
  org.hibernate.id.UUIDHexGenerator
  不产生的IETF RFC 4122
  兼容UUID值;考虑使用
  org.hibernate.id.UUIDGenerator而不是


所以,我想切换到org.hibernate.id.UUIDGenerator,现在的问题是我应该怎么告诉它Hibernate的发电机。我看到一些人用它作为一个休眠的UUID - 所以这是我尝试过,但阴性结果:

  @Id
@GeneratedValue(发电机=休眠的UUID)
@GenericGenerator(NAME =休眠的UUID的策略=休眠的UUID)
@Column(名称=的「uuid」,独特= TRUE)
私人字符串UUID;


解决方案

应该是 UUID2

  ...
@GenericGenerator(名称=的「uuid」,战略=UUID2)
...

请参阅 5.1.2.2.1。各种附加发电机的。

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:

Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values; consider using org.hibernate.id.UUIDGenerator instead

So i want to switch to org.hibernate.id.UUIDGenerator, now question is how should I tell it to Hibernate's generator. I saw some guys 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;

解决方案

It should be uuid2:

...
@GenericGenerator(name = "uuid", strategy = "uuid2")
...

See 5.1.2.2.1. Various additional generators.

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

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