在Hibernate注释上分配生成器类 [英] Assigned Generator Class on Hibernate Annotations
问题描述
当我使用xml方法时,我将生成器类设置为分配。
在分配一个员工ID之前必须检查某些逻辑,所以我不能自动生成
。
< id name =idtype =stringcolumn =emp_id>
< generator class =assigned>
< / generator>
< / id>
但是我也在研究注释类型和注释,因为框架正在消失从
配置文件。但我找不到任何生成类型匹配指定的值
public class Employee {
String id;
@column(name =emp_id,unique = true)
public String getID(){
return id;
$ b 这是否意味着我不需要添加任何序列生成器注释何时分配?谢谢
解决方案 只需使用 @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 it
automatically.
<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 from
configuration 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注释上分配生成器类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文