Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate String Primary Key with Annotation

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

How can I configure a String primary key with annotations?

like image 499
sedran Avatar asked Mar 19 '26 01:03

sedran


1 Answers

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;
like image 142
JB Nizet Avatar answered Mar 21 '26 14:03

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!