-->
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.  [ 3 posts ] 
Author Message
 Post subject: one-to-one mapping problem
PostPosted: Thu Jan 29, 2009 11:48 pm 
Newbie

Joined: Wed Sep 10, 2008 7:56 am
Posts: 1
Hi ,
Can anybody help me out how to do the OR Mapping for the following with Hibernate.

Table Users:
Users(int user_id, varchar username)
user_id is primary key and auto increment column.


Table Addresses:
Addresses(int address_id, int user_id, varchar city, varchar state,...)

address_id is primary key and auto increment column.


Code:

public class User
{
int userId;
String username;
Address address;

// setters n getters

}

public class Address
{
int addressId;
int userId;
String city;
// setters n getters
}


Top
 Profile  
 
 Post subject: One-to-One Mapping
PostPosted: Fri Jan 30, 2009 12:11 am 
Newbie

Joined: Sat May 20, 2006 6:06 am
Posts: 1
Try to use the following mappping.
<class name="person" table="PERSON">
<id name="id" column="PERSON_ID">
<generator class="foreign">
<param name="property">employee</param>
</generator>
</id>
...
<one-to-one name="employee"
class="Employee"
constrained="true"/>
</class>


<one-to-one name="employee" class="Employee" property-ref="person"/>

_________________
Ram Parashar


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2009 9:50 am 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
check this links out http://www.allapplabs.com/hibernate/hibernate_o_r_mapping_one_to_one_element.htm,
http://www.xylax.net/hibernate/onetoone.html

regards,


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