Java – @ generatedvalue annotation

I have an entity that has a non - key column and I set it to auto - generate in my database

I can't use @ generatedvalue because as far as I know, it only applies to key fields

Given this situation, how can I indicate that non key columns are automatically generated?

Solution

If you are not interested in having the JPA provider generate the key for you when you create the object, but just want to make sure that the database remains updated when it is created and is using Hibernate: you can use @ org hibernate. annotations. Generated note:

The annotated property is generated by the database.

According to this answer to a similar question, there seems to be no simple way for your JPA to generate value for you

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>