confusing error message when OneToOne has a duplicate on one end
----------------------------------------------------------------
Key: HHH-6604
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6604
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.6, 4.x
Environment: originally found with hibernate 3.6.6 and MS SQL Server; also
happens when run in a hibernate unit test.
Reporter: Laura Dean
Priority: Minor
Attachments: OneToOne-error-message.patch
Suppose I have a Trousers entity with id 1, that knows about its TrousersZip, which has id
2. That is, my Trousers has zip_id = 2. (This part of the example comes from
Hibernate's unit tests.)
Suppose the Trousers has a TrousersHanger, also one-to-one, but mapped on the
TrousersHanger side. That is, the hanger points to its Trousers.
Now suppose I put two TrousersHangers into the database, both pointing at the same
Trousers. (Naughty, I know; in the real world, it happened because of HHH-6484.)
When I then try to load the Trousers from the database, I get a very confusing error
message:
org.hibernate.HibernateException: More than one row with the given identifier was found:
2, for class: org.hibernate.test.annotations.onetoone.Trousers
The message confuses me for three reasons:
1. I have only one row in the Trousers table.
2. That one row has ID 1.
3. My actual problem is with duplicate TrousersHangers, and neither one of them has ID 2.
In other words, where the heck did ID 2 come from?
As it turns out, hibernate finds the Trousers by id, then finds the Trousers by zip_id (to
populate the TrousersZip object). It doesn't care about the duplicate results in the
first query, but it does care the second time. But the error message doesn't mention
that its ID is actually the zip_id, and a person could waste quite a bit of time before
figuring out that the TrousersZip had anything to do with it. (Well, maybe not in this
contrived example with only 3 entities. But in the real world, yeah.)
I've attached a junit test, adding to hibernate's own OneToOneTest.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira