-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate mapping question
PostPosted: Tue Aug 14, 2007 2:23 pm 
Newbie

Joined: Tue Aug 14, 2007 1:13 pm
Posts: 2
Hibernate version:Hibernate 3.2.4.sp1

//User.java
public class User {

long userId;
String fName;
Address address;

//all getter and setters and constructor

}

//Address.java
public class Address {

long addressId;
long userId;
String street;

//all getter and setters and constructor

}


User object has just a ref. to Address object. I need little help as to what kind of mapping I need to use in Address.hbm.xml.

Not sure if the User mapping is right, should I use one-to-one?

I like to create the User obj.; create Address obj.; set Address obj in User obj. and then save the User obj (which should also save the Address obj. in db)


Mapping – in User :

Code:
<class name="com.hibernate.User">

<id name="userId" column="user_Id">
                 <generator class="sequence">
                  <param name="sequence">User_SEQ</param>
                </generator>
        </id>
<!-- other properties-->
<many-to-one name="address" class="com.hibernate.Address" column="address_id_pk"
                     unique="true" cascade="all"   />
</class>

<!--Mapping – in Address -->

<class name="com.hibernate.Address">
        <id name="addressId" column="address_id_pk">
                 <generator class="sequence">
                  <param name="sequence">address_SEQ</param>
                </generator>
        </id>


…"What should be here to ref. the (pK in user table ie userId)"



</class>


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 2:40 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
There are some fine examples of this in the docs:
http://www.hibernate.org/hib_docs/refer ... tions.html


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