-->
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.  [ 1 post ] 
Author Message
 Post subject: need help mapping a one-to-one relationship
PostPosted: Thu Apr 13, 2006 1:05 pm 
Newbie

Joined: Sun May 22, 2005 4:21 pm
Posts: 10
I am using Hibernate 3.1 and Oracle 9i. I am trying to set up a one-to-one relationship between the PERSON table and the EMPLOYEE table, where EMPLOYEE should be assigned the same primary key as PERSON.

I have set up the mapping files the way the Hibernate documentation showed:

Mapping documents:
Code:
<class name="org.Person" table="PERSON">
    <id name="personId" column="PERSON_ID">
    <generator class="increment">
    </generator>
    </id>
    <one-to-one name="employee" class="org.Employee" cascade="save-update">
    </one-to-one>
</class>

Code:
<class name="org.Employee" table="EMPLOYEE">
    <id name="id" column="EMPLOYEE_ID">
        <generator class="foreign">
            <param name="property">person</param>
        </generator>
    </id>
    <one-to-one name="person" class="org.Person" constrained="true">
    </one-to-one>
</class>   


Code to save Person:
Code:
1.) Person person = new Person();
2.) Employee employee = new Employee();
3.) person.setEmployee(employee);       
4.) employee.setPerson(employee);      
5.) dao.savePerson(person);


When I run this code, I get an exception at line 5 saying the following:
Code:
nested exception is org.hibernate.HibernateException: Unable to resolve property: person


If I save the person object first between lines 1 and 2, I do not get the same exception, but the employee object still does not get saved when the person is saved again at line 5.

I am wondering if there is anything special I need to do in the getters and setters of the Person and Employee classes. Right now all I am doing is passing in the object.
setPerson method of Employee class:
Code:
public void setPerson(Person person) {
    this.person = person;
}


setEmployee method of Person class:
Code:
public void setEmployee(Employee employee) {
    this.employee = employee;
}


Can anyone tell me what I need to do?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.