问题描述
Hibernate新手在这里。我正在研究一个简单的Hibernate映射文件。当我使用xml方法时,我将生成器类设置为分配。
在分配一个员工ID之前必须检查某些逻辑,所以我不能自动生成
。
只需使用 @Id 注释,财产是你的实体的标识符。你不需要使用 @GeneratedValue 注释,因为我不认为你想让hibernate为你生成这个属性。
@Id
字符串ID;
Hibernate newbie here. I am working on a simple Hibernate mapping file.When I am using the xml approach, I set the generator class to assigned.There are certain logic that must be checked before an employee id is assigned so I cant generate itautomatically.
<id name="id" type="string" column="emp_id"> <generator class="assigned"> </generator> </id>But I am also studying the annotation type and annotation seems to be in thing nowadays as frameworks are moving away fromconfiguration files. But I cant find any generation type to match the assigned value
public class Employee{ String id; @column(name="emp_id", unique=true) public String getID(){ return id; } }Does this mean that I dont need to add any sequence generator annotation when it is assigned? Thanks
解决方案Just use the @Id annotation which lets you define which property is the identifier of your entity. You don't need to use the @GeneratedValue annotation because I don't think you want hibernate to generate this property for you.
@Id String id;
这篇关于在Hibernate注释上分配生成器类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!