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.  [ 5 posts ] 
Author Message
 Post subject: Two one-to-one relationship
PostPosted: Thu Dec 11, 2003 12:15 pm 
Newbie

Joined: Thu Dec 11, 2003 12:10 pm
Posts: 16
HI!

How can I make two one-to-one relationship to the same class???

example:

class Application{
Account bankAccount;
Account communityAccount;
}

class Account{
....
}

Tnx!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:14 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Just the way you wrote your classes, I'd say.

I think two one-to-one associations in class1 refering to class2 will force you to use foreign keys (in the database model) which refer to the primary key of the table corresponding to class2.

Usually (which means only a single one-to-one association is used) no extra columns are required, while the linked table rows use the same primary key.

Just read the reference for more information on this topic:
http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-9


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:43 pm 
Newbie

Joined: Thu Dec 11, 2003 12:10 pm
Posts: 16
My Application's mapping:
Code:
<subclass name="Application">
   <one-to-one name="communityAccount" class="CommunityAccount" constrained="true"/>
   <one-to-one name="bankAccount" class="BankAccount" constrained="true"/>
</subclass>


The relationship in Account's mapping
Code:
<many-to-one name="owner" column="owner_id" class="Application"/>


My Table Accounts in DataBase
Code:
+------------+---------------------+----------+----------+
| account_id | creationDate        | owner_id | amount   |
+------------+---------------------+----------+----------+
|          1 | 2003-12-11 14:11:51 |        1 |   52.7   |
|          2 | 2003-12-11 14:11:51 |        1 |   41.8   |


The application is a singleton stored in my DataBase in the first row(id 1) has two accounts,
when I load this row Hibernate throw an exception: More than one row to unique association!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2003 6:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Something wrong with your PK column ? or something

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Thanks!!
PostPosted: Fri Dec 12, 2003 7:13 am 
Newbie

Joined: Thu Dec 11, 2003 12:10 pm
Posts: 16
Thank All!!

I was resolve this with bag mapping.

Tnx!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.