I need help with one-to-one mapping.
I have two classes People and PeopleLogin
They both share the same primary key. People can have 0-1 people login but for each entry in people login there has to be people record.
When I do save on people with peoplelogin
then hibernate tries to "insert to people" and update on "peoplelogin" where it should try to do insert on both the tables.
mapping looks likebelow
<class name="PeopleLogin" table="people_logins" dynamic-insert="false" dynamic-update="false">
<id name="id" column="PERSON_ID" class="People" type="long" unsaved-value="null">
<generator class="foreign">
<param name="property">people</param>
</generator>
</id>
<one-to-one name="people" class="People" />
</class>
<class name="People" table="Peoples" dynamic-insert="false" dynamic-update="false">
<id name="id" column="PERSON_ID" type="long" unsaved-value="null">
<generator class="increment"/>
</id>
<one-to-one name="login" class="PeopleLogin" constrained="false" cascade="all"/>
</class>
My save looks like
People people = new People();
PeopleLogin login = new PeopleLogin();
people.setLogin(login)
session.save(people);
Hibernate: insert into Peoples (PERSONTYPE_ID, PRIMARY_EMAIL, PERSON_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update people_logins set LOGIN_NAME=?, PASSWORD=?, STATUS_FLAG=?, STATUS_DATE=?, CREATE_DATE=?, CREATED_BY=?, UPDATED_BY=?, UPDATE_DATE=? where PERSON_ID=?
Why? Please help
I donot want to have bidirectional mapping from people-login to People
I just need unidirectional from people to peopleLogin but I couldn't.
Vandana
|