两个自动生成的ID在春季单一实体 [英] Two auto generated IDs in Spring single entity

查看:152
本文介绍了两个自动生成的ID在春季单一实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成两个ID(列值)春季与注解。
会有什么解决办法,如果我需要说明,标识和UUID生成的ID 2汽车,我会用UUID与下面的生成:

I need to generate two IDs (column values) in Spring with Annotations. What would be the solutions if I need 2 IDs auto generated with annotations, ID and UUID, I would use UUID generated with the following:

@Id 
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Column(name = "uuid", unique = true)
private String uuid;

,但我不会能够使用@Id注释的同时并不能自动生成ID(第二产生磁场)

but I would not be able to use the @Id annotation at the same time and can not auto generate the ID (second generated field)

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;

什么将汽车的最佳解决方案产生两列编号和UUID,因为只有一个@Id只有一个被创建,而另一个为空?
我需要用Hibernate的一些解决方案,而不是编程生成他们中的一个。

What would be the best solution to auto generate two columns ID and UUID, since with only one @Id only one is created and the other is null? I need some solution with Hibernate, not programatically generating one of them.

推荐答案

我临时决定使用UUID.randomUUID(),但我还是希望能听到有关通过Hibernate生成无论IDS其他可能的解决方案。

I have temporary decided to use UUID.randomUUID(), but I am still eager to hear about other possible solutions for generating both ids through hibernate.

这篇关于两个自动生成的ID在春季单一实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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