带有注释的休眠字符串主键 [英] Hibernate String Primary Key with Annotation
本文介绍了带有注释的休眠字符串主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用其主键为String的注释创建Privilege类.我将在插入时手动分配它们.因此,无需休眠即可为其生成值.我正在尝试做这样的事情:
I am trying to create a Privilege class with Annotations whose Primary Key is a String. I will assign them manually while inserting. Therefore no need for hibernate to generate a value for it. I'm trying to do something like that:
@Id
@GeneratedValue(generator = "assigned")
@Column(name = "ROLE_NAME", nullable = false)
private String roleName;
但是它抛出了异常:
Caused by: org.hibernate.AnnotationException: Unknown Id.generator: assigned
如何配置带有注释的String
主键?
How can I configure a String
primary key with annotations?
推荐答案
由于roleName
不会自动生成,因此您不应该使用@GeneratedValue
对其进行注释:
Since the roleName
is not auto-generated, you should simply not annotate it with @GeneratedValue
:
@Id
@Column(name = "ROLE_NAME", nullable = false)
private String roleName;
这篇关于带有注释的休眠字符串主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文