-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to set the association column in one-to-one mapping?
PostPosted: Tue May 04, 2004 4:17 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
hello everyone,
I need advices about the imaginary scenario below;

Table Person : PID, HotelID

Table Hotel: HID, Name, Location

Class Person : Long PID, Hotel hotel

Class Hotel : Long HID, String name....


HotelID is the foreign key references Hotel ID in Person
The relation is : each person stays in one hotel. (one-to-one)
hotel can have many person or "no person"
So, the Hotel table holds no reference to the Person table.

I mapped them as (Dont consider syntax mismatches)

<class name= Person.............
<id name = PID .....

<one-to-one name = "hotel" class= "Hotel">
</class>

<class name = "Hotel........
<id name = HID........
<property ....
</class>

But, as you see it is wrong, this one to one relation constructs person.PID = hotel.HID but I want it to generate person.HID = hotel.HID..
Is it possible to use one-to-one,many to one associations on that scenario
or not?
I mean can I tell hibernate this:

Join these 2 tables on "that" columns not pk columns with one-to-one?
(person.HotelID = Hotel.HID)

Note: I can't change the db schema and I can't write Sql queries. I want all thing to happen in mapping file

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 4:21 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
just use a many to one, the important for you is the to-one end


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 4:31 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I dont understand, Where is the many-to-one relation, can u write the mapping file for many to one relation pls

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 4:36 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
<class name= Person.............
<id name = PID .....

<many-to-one name = "hotel" class= "Hotel" column="here you can specify the fk">
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 5:02 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I did, but now it gives
java.sql.SQLException: Io exception : Socket closed
...

why?, it did not give when I comment many-to-one


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 5:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
it is a connexion problem now.... seems not to be related with the mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 5:10 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
But when I comment the <many-to-one ...> line, it works.

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 5:19 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
thanks very much, it worked!
Have a good day my friend

_________________
-developer


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