-->
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 problem
PostPosted: Thu Apr 29, 2004 11:11 am 
Newbie

Joined: Thu Apr 29, 2004 10:29 am
Posts: 13
I'm trying to make a one-to-one relation, i have two classes "Person" and "Phone". The problem is that when i try to insert a person who have a phone. Hibernate insert the phone right, and the person right.. but it doesn't save the relation attribute (the foreign key FK_idPhone in the person table).

This is just a test i'm doing to try to save a simple relation.

Hibernate version: 2.1.2
Database: postgre 7.4.2

Code:
public class Person {
   private String name;
   private Long id;
   private Phone phone;
   //getters and setters.....

}


Code:
public class Phone {
   private String number;
   private Long id;
   //getters and setters.....
}


Code:
<hibernate-mapping>
   <class name="uy.edu.ort.domain.services.ejb.Person" table="person">
      <id name="id" column="id" type="long">
         <generator class="increment"/>
      </id>
      <property name="name"/>
      <one-to-one name="phone" constrained="true" cascade="all" class="uy.edu.ort.domain.services.ejb.Phone"/>
   </class>

   <class name="uy.edu.ort.domain.services.ejb.Phone" table="phone">
      <id name="id" column="id" type="long">
         <generator class="increment"/>
      </id>
      <property name="number"/>
   </class>
</hibernate-mapping>


Code:
   //This is the test
   Person user = new Person();
   Phone phone = new Phone();
   user.setName("Guille");
   phone.setNumber("123");
   user.setPhone(phone);
   session.save(user);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 4:47 pm 
Newbie

Joined: Mon Feb 16, 2004 11:28 pm
Posts: 16
Wouldn't your generator class be "foreign" on the phone table since its using the same key as person. Your configuration is generating a new one, correct?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 5:11 pm 
Newbie

Joined: Thu Apr 15, 2004 12:00 pm
Posts: 13
Refer Hibernate documentation "5.1.11. one-to-one" section


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.