Why does Hibernate believe that @GeneratedValue is fundamentally wrong?

I just read the Hibernate documentation and came across a warning on this page

http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#d0e1150

"Warning The Hibernate team has always considered such a design to be fundamentally incorrect. Try to fix your data model before using this function." Regarding the generation of a partial identifier

Can someone explain to me a little more in detail what is really wrong with this? Why is Hibernate looking down at the generated values? Does this include auto-incrementing in Hibernate?

Thanks,

+4
source share
2 answers

The warning is not related to using @GeneratedValue in a class that has only one id field. A warning about using @GeneratedValue in one column of a composite key, which is a very strange use case (I have never seen the need for something like this for 12 years).

So, a warning: if you need to use @GeneratedValue in a composite key, then look at your model, because there is a high probability that something is wrong with it.

If you think this does not answer your question, can you give an example where you might need this function?

+2
source

There is a surrogate identifier, which should always be the only property (and therefore a column) that is declared at the database level as the primary key. And there is a business identifier (aka a business key), which has a business meaning and can consist of several properties (and, therefore, columns).

There is nothing wrong with creating a single surrogate identifier. Most likely, the Hibernate command means that the generation of some parts of the business identifier (in the case of several properties) is incorrect.

0
source

All Articles