带注释的休眠字符串主键 [英] Hibernate String Primary Key with Annotation

查看:32
本文介绍了带注释的休眠字符串主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用主键是字符串的注释创建一个权限类.我将在插入时手动分配它们.因此不需要休眠为其生成值.我正在尝试做这样的事情:

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;

但是它抛出了那个异常:

But it throws that exception:

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屋!

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