Reputation: 20063
I was just reading the Hibernate documentation and came across the warning on this page
http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#d0e1150
"Warning The Hibernate team has always felt such a construct as fundamentally wrong. Try hard to fix your data model before using this feature." with regards to Partial identifier generation
Can someone explain to me in a little more detail what is actually wrong with this? Why does Hibernate look down on generated values? Does that include auto incremented values in Hibernate?
Thanks,
Upvotes: 4
Views: 227
Reputation: 5410
There is a surrogate identifier, which should always be a single property (and thus column) that at the database level is declared a primary key. And there is a business identifier (aka business key), which has business meaning and may consists of several properties (and thus columns).
There is nothing wrong with generating a single surrogate identifier. What the Hibernate team most likely meant is that generation of some parts of a business identifier (in case of multiple properties) is wrong.
Upvotes: 0
Reputation: 29977
The warning is not about using @GeneratedValue on a class that has only one id field. The warning is about using @GeneratedValue in one column of a composite key, which is a very odd use case (never seen a need for something like this in 12 years).
So the warning is: If you need to use @GeneratedValue in a composite key, then review your model, because there's a big chance that there's something wrong with it.
If you think that this doesn't answer your question, can you provide an example where you might need this feature?
Upvotes: 2