I have an entity which has a non-key column which I’ve set as auto-generated in my DB.
I cannot use @GeneratedValue because it works only for key fields as far as I understand.
Given this case, how do I indicate that the non-key column is auto-generated?
If you are not interested in having your JPA provider generate the key for you on object creation, but only want to make sure it stays updated when the database creates it, and are using Hibernate: you can use the
@org.hibernate.annotations.Generatedannotation:According to this answer to a similar question It doesn’t look like there is a simple way to have your JPA generate the value for you.