-->
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.  [ 7 posts ] 
Author Message
 Post subject: One-to-one...I'm losing it...
PostPosted: Fri Jul 15, 2005 12:43 pm 
Beginner
Beginner

Joined: Fri Jul 15, 2005 12:26 pm
Posts: 37
Every guy has a house. Every car has a house. How oh how do I map a one-to-one relationship between two foreign keys? I'm losing it.

Image

Guy.hbm.xml

<property name="houseId" column="HOUSE_ID" type="java.lang.Long" insert="false" update="false"/>

<one-to-one name="car" class="Car" property-ref="houseId"/>



Car.hbm.xml

<property name="houseId" column="HOUSE_ID" type="java.lang.Long" insert="false" update="false"/>

<one-to-one name="guy" class="Guy" property-ref="houseId"/>



Still tries to join to one or the other primary keys...Am I crazy to think you should be able to join on two not-that-arbitray fields?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 12:55 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
No you are not crazy. yet.

Have you tried the foreign-key attribute?

[url]http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-declaration-onetoone
[/url]
Etienne.


Top
 Profile  
 
 Post subject: Re: One-to-one...I'm losing it...
PostPosted: Fri Jul 15, 2005 1:13 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Tremelune wrote:
Every guy has a house. Every car has a house. How oh how do I map a one-to-one relationship between two foreign keys? I'm losing it.


Still tries to join to one or the other primary keys...Am I crazy to think you should be able to join on two not-that-arbitray fields?


I'm curious as to why you would want to join a Guy to a Car using the houseId ?

I would also think you would map the Guy and Car as <many-to-one> with House since, theoretically at least, more than 1 guy can have the same house.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 2:16 pm 
Beginner
Beginner

Joined: Fri Jul 15, 2005 12:26 pm
Posts: 37
Perhaps bad example, but guy-house is one-to-one and and house-car is one-to-one...I want to join them directly to avoid uglier and train wreckier code:

guy.getHouse.getCar()...

Could just be

guy.getCar();

I'm too dumb to figure out the foreign-key attributes...I started reading about various constraints and my eyes glazed over.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 7:11 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
Have you tried formula?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 6:26 pm 
Beginner
Beginner

Joined: Fri Jul 15, 2005 12:26 pm
Posts: 37
Formula?? I've checked out a couple of books, and they only seem to cover the most common one-to-one mappings...Rrr...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 11:18 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Tremelune wrote:
Formula?? I've checked out a couple of books, and they only seem to cover the most common one-to-one mappings...Rrr...


I'm pretty sure formula is new in H3 and probably isn't in any of the books yet. Check out the reference docs.


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