I will first briefly describe the logical scenario: I have a type of object called a REPO. I also have a type of object called a TRADE. A TRADE object can exist in it's own right. A REPO object must have an opening TRADE object and a closing TRADE object.
So I have two database tables: REPO and TRADE. The TRADE table has the REPO FK REPO_ID.
I have two Java classes: Repo and Trade. The Repo class has the two properties: Trade openingTrade and Trade closingTrade. The Trade class has the property Repo repo.
And I have the following hibernate mapping in Trade:
Quote:
<many-to-one name="repo" column="REPO_ID" not-null="false"/>
And the following mapping in Repo:
Code:
<one-to-one name="openingTrade" property-ref="repo" lazy="false"/>
<one-to-one name="closingTrade" property-ref="repo" lazy="false"/>
I can actually create and save the trades and the repo record. But when I go to read the Repo record, I get the following error:
Code:
org.springframework.orm.hibernate3.HibernateSystemException: More than one row with the given identifier was found: 3, for class: com.domain.Repo; nested exception is org.hibernate.HibernateException: More than one row with the given identifier was found: 3, for class: com.domain.Repo
Now I think I understand what the message is telling me: if this is a genuine one-to-one mapping, then there shouldn't be two trade records referencing the same repo record.
But how do I do a one-to-many mapping without having a collection?
Or am I just looking at this problem all wrong?
Thanks for your help.