JPA:覆盖自动生成的ID [英] JPA: Override Auto generated ID
本文介绍了JPA:覆盖自动生成的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Employee类中有以下定义:
$ p $ $ $ $ $ @ $
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name =employee_id)
private Integer employeeId;
现在我想用现有员工ID导入现有员工。即使我在保存之前设置员工ID,分配的ID也会被忽略,并自动递增ID被存储。我们如何覆盖这个?
解决方案
我发现有相同问题的重复线程。
在休眠状态下绕过generatedvalue p>
所以最后我写了自己的生成器来解决这个问题。
感谢所有人的帮助:)
I have following definition in Employee class
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "employee_id")
private Integer employeeId;
Now I want to import existing employees with existing employee IDs. Even if I set the employee ID before saving, the assigned ID is ignored and auto incremented ID is stored. How do we override this?
解决方案
I found a duplicate thread with same issue. bypass generatedvalue in hibernate
So finally I wrote my own generator to solve the issue.
Thanks all for the help :)
这篇关于JPA:覆盖自动生成的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文