-->
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: Simple one-to-one mapping
PostPosted: Mon Jul 12, 2004 11:57 am 
Newbie

Joined: Mon Jul 12, 2004 11:54 am
Posts: 2
Can someone please post an example of a simple one-to-one realationship between two classes, specifically the xml mapping.

I cannot get the example in the docs to work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 9:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
From the online docs.

For a primary key association, add the following mappings to Employee and Person, respectively.

<one-to-one name="person" class="Person"/>

<one-to-one name="employee" class="Employee" constrained="true"/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 9:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If this is the example you are refering to then we will need to see more information.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 4:54 am 
Newbie

Joined: Mon Jul 12, 2004 11:54 am
Posts: 2
All the examples on this site, and in the manual just say to add those 2 lines, but to where!?!

I have a very simple example, just two classes, BOOK and BARCODE. I want them to have the same primary key. Here's my mappings:

<hibernate-mapping>
<class
name="Barcode"
table="tbl_BARCODE"
dynamic-update="false"
dynamic-insert="false">

<id name="id"
column="ID"
type="java.lang.Long"
unsaved-value="-1">
<generator class="foreign">
<param name="property">Barcode</param>
</generator>
</id>

<one-to-one
name="id"
class="Book"
cascade="none"
outer-join="auto"
constrained="false"/>

<property
name="barcode_value"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="BARCODE_VALUE"/>

</class>
</hibernate-mapping>

-----------------------------------------------------

<hibernate-mapping>
<class
name="Book"
table="tbl_BOOK"
dynamic-update="false"
dynamic-insert="false">

<id name="id"
column="ID"
type="java.lang.Long"
unsaved-value="-1">
<generator class="native">
</generator>
</id>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="NAME"/>

<one-to-one
name="bc"
class="Barcode"
cascade="all"
outer-join="auto"
constrained="false"/>

</class>
</hibernate-mapping>

Do I need to add a reference from BOOK to BARCODE , and vice versa?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 11:05 am 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
I *think* you only need to declare them both if you are going to have accessor methods in both classes:

book.getBarCode();

barCode.getBook();


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.