Issue Details (XML | Word | Printable)

Key: HHH-2128
Type: Bug Bug
Status: Resolved Resolved
Resolution: Rejected
Priority: Blocker Blocker
Assignee: Unassigned
Reporter: Patrick Moore
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

data corruption using one-to-one mapping

Created: 03/Oct/06 05:52 PM   Updated: 03/Oct/06 08:00 PM
Component/s: core
Affects Version/s: 3.2.0.cr4
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive hibernatetests.zip (3 kB)

Environment: hsqldb 1.8.0


 Description  « Hide
Please notice that this situation arose from the most minimal definition. Using the 'defaults' is what caused this issue!

See attached zip for definitions and reproduction test case.

Steps:
1. define two classes (Primary, Secondary) that have a one-to-one relationship.
2. save a primary with no assigned secondary object.
3. save another primary with a secondary object.
4. retrieve the first primary and it will have the secondary object saved in step 3.
5. retrieve the second primary and it will have no secondary object.

Suggested solution:
require that 'one-to-one' enforce an implicit non-null requirement between primary and secondary.


 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
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).

Patrick Moore added a comment - 03/Oct/06 07:16 PM
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.

Patrick Moore added a comment - 03/Oct/06 07:21 PM
... 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 :-)

Christian Bauer added a comment - 03/Oct/06 07:25 PM
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.

Patrick Moore added a comment - 03/Oct/06 08:00 PM
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?