-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: One-To-One Bi-Directional Relationship... sort of
PostPosted: Tue May 19, 2015 9:40 am 
Newbie

Joined: Tue May 19, 2015 9:21 am
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: One-To-One Bi-Directional Relationship... sort of
PostPosted: Tue May 19, 2015 9:58 am 
Newbie

Joined: Tue May 19, 2015 9:21 am
Posts: 2
Ok - wait. I just realised this is a REALLY dumb question.

Obviously if the REPO_ID is the FK in the TRADE table, there is no-way to know which TRADE is the openingTrade and which is the closingTrade.

I will do things differently...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.