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: one-to-one
PostPosted: Tue Dec 14, 2004 11:36 am 
Newbie

Joined: Tue Dec 14, 2004 11:21 am
Posts: 2
Hi,

Some basic question :

I have a one-to-one mapping between to classes, for example:
class Person{
private int id;
private int age;
private Name name;

// getters/setters for all properties
}

and

class Name{
private int id;
private String firstName;
private String lastName;

// getters/setters for all properties
}

the id's are both mapped as "sequence"-generated.

I have a test class with following code:

Name name = new Name();
name.setFirstName("Oscar");
name.setLastName("Wilde");

Person p = new Person();
p.setAge(47);

session.save(p);

Will hibernate also insert a record into table "Names" ??
Or do I need to save the name first before I attache it to Person?

Mapping files looks like:

Name.hbm.xml:
<?xml version="1.0"?
...
>
<hibernate-mapping>
<class name="com.bebop.business.Name" table="Names">
<id name="id" type="int" column="name_id" unsaved-value="0">
<generator class="sequence">
<param name="sequence">seq_names</param>
</generator>
</id>
<property name="firstName" column="firstname" type="string"/>
<property name="lastName" column="lastname" type="string"/>
</class>
</hibernate-mapping>

Person.hbm.xml:
<?xml version="1.0"?
...
>
<hibernate-mapping>
<class name="com.bebop.business.Person" table="Persons">
<id name="id" type="string" >
<column name="uid" length="16"/>
<generator class="uuid.hex"/>
</id>
<property name="age" column="age" type="int"/>
<one-to-one name="name" class="com.bebop.business.Name"/>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 12:06 pm 
Newbie

Joined: Tue Dec 14, 2004 11:21 am
Posts: 2
Argh ... if I just searched a bit longer !!!

"cascade" is the answer !!!

Regards.


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.