|
[
Permalink
| « Hide
]
Christian Bauer added a comment - 03/Oct/06 06:03 PM
The only valid mapping in your tests is the second mapping. You obviously can't use a shared primary key one-to-one mapping with automatically assigned native primary keys. Re-submit this test with only valid mappings (or one mapping that is valid).
I filed this because the code didn't detect this error and because this would result in quiet data corruption. It is only by pure luck that I happened to discover this issue.
And .. no it is not 'obvious' that this would cause a problem. Hibernate seems to be smart and in many cases it will quietly add a column if needed to manage a collection. In this case I was fully expecting that it would add such a column to enforce the relationship. I would suggest that the one-to-one mapping result in an added column to enforce the 1-1 relationship. It is always possible to turn off this as default behavior by using the property-ref attribute. ... I should add I spent a hours tying to figure out why my data was completely corrupted. It was not obvious that the problem was related to the database order of the data!
Concider it a testiment to Hibernate -- that I spent a large amount time assuming that I had some programming bug :-) Rejecting this. Please read again what I wrote (has nothing to do with magic database constraints). It should be obvious that Hibernate can not enforce all mappings to be "correct". Yours are wrong.
This is not a case of trying to protect against all bad choices. This is a case of stopping the user from trying to define something that is clearly *incorrect* and shooting themselves in the foot. (And data corruption is a pretty big hole).
I am only suggesting making it so that the definition would fail on an 'obviously' wrong configuration. If it is obviously wrong, shouldn't Hibernate by default refuse to accept it? |
||||||||||||||||||||||||||||||||||||||||||||||||||