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