-->
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.  [ 6 posts ] 
Author Message
 Post subject: One-to-one mapping question
PostPosted: Sat Dec 08, 2007 6:43 pm 
Newbie

Joined: Fri Sep 28, 2007 3:45 pm
Posts: 9
Hi all. I have a newbie question about a mapping. I have two tables. One, the primary table, is called Building, while the second one is used to stored Building addresses (called Address). There is an one-to-one mapping between these two tables, which are related through an id property, called bid. This is primary key for the Building table and foreign key for the table Address.

According to the current policy a building usually has an address but may not have one sometimes (if its a new entry). How could I write the above mapping in my hbm files? Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 09, 2007 1:53 pm 
Newbie

Joined: Fri Sep 28, 2007 3:45 pm
Posts: 9
anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 09, 2007 5:48 pm 
Newbie

Joined: Wed Nov 21, 2007 11:03 am
Posts: 8
I think it's a simple situation due to what you described. It's an one-to-one non-bidirectional relation and Building doesn't need to know about Address , so if one is newly built and hasn't got an address, leave it that way. Once you have address for it, create new Address object with primary key is the bid.


Last edited by jaymz on Mon Dec 10, 2007 8:42 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 09, 2007 8:28 pm 
Newbie

Joined: Fri Sep 28, 2007 3:45 pm
Posts: 9
could you show me an example of how I could write this? My current one-to-one mapping does not work :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 8:41 am 
Newbie

Joined: Wed Nov 21, 2007 11:03 am
Posts: 8
The mapping file should look like this:


Quote:
<class name="Address" table="address">

<id name="bid" column="bid">
<generator class="assigned">
</id>
...
<one-to-one name="building" class="Building" constrained="true"/>
</class>

<class name="Building" table="building">
<id name="bid" column="bid">
<generator class="native"/>
</id>
...
</class>


Notice that generator of Address is "assigned", indicate that Address must have the same identifier as Building.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 23, 2007 5:56 pm 
Newbie

Joined: Fri Sep 28, 2007 3:45 pm
Posts: 9
jaymz wrote:
The mapping file should look like this:


Quote:
<class name="Address" table="address">

<id name="bid" column="bid">
<generator class="assigned">
</id>
...
<one-to-one name="building" class="Building" constrained="true"/>
</class>

<class name="Building" table="building">
<id name="bid" column="bid">
<generator class="native"/>
</id>
...
</class>


Notice that generator of Address is "assigned", indicate that Address must have the same identifier as Building.





Hey,

I just tried this. But the data I get are nulls. Here is my mappings

<hibernate-mapping>
<class name="org.app.foundation.beans.Gipeda" table="buildings" catalog="buildings_gr">
<id name="gid" type="string">
<column name="id" length="35" />
<generator class="assigned" />
</id>
.............................................
<one-to-one name="map" class="org.app.foundation.beans.GeoMap" constrained="true"/>
</class>
</hibernate-mapping>


and

<hibernate-mapping>
<class name="org.app.foundation.beans.GeoMap" table="maps" catalog="buildings_gr">
<id name="gid" column="gid">
<generator class="native"/>
</id>
<property name="latitude" type="string" not-null="true" />
<property name="longitude" type="string" not-null="true" />
</class>
</hibernate-mapping>

But what I get is null data. Actually a building may not have a geomap (or can have at most one). But i would expect at least the gid of the geomap object to be populated. But I dont get data even for the entries that do have a map associated. Thanks for the help


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