Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Increment not working for Entity class with composite Key

I want one of my Composite key elements to be auto incremented and I am using Embedded Key for my entity class and therefore I am not able to use the Generated Values Annotation to solve the problem since @GeneratedValue annotation is ignored when using @Embeddable or @EmbeddedId.

like image 311
gigin26 Avatar asked Oct 23 '25 18:10

gigin26


1 Answers

You cannot use @GeneratedValue with @EmbeddedId, @Embeddable or @IdClass, the @GeneratedValue annotation gets ignored. You have to manually assign the values.

Check the following references :

https://java.net/jira/browse/GLASSFISH-13567

https://forums.hibernate.org/viewtopic.php?p=2393944&sid=57b20ef2c7de6f6bcba632130987bc22

like image 53
tharindu_DG Avatar answered Oct 26 '25 08:10

tharindu_DG



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!