-->
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: problem with cascade update in one-to-one relation
PostPosted: Thu Dec 22, 2005 10:04 pm 
Newbie

Joined: Wed Nov 09, 2005 11:03 am
Posts: 5
Hi,

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2

I have problem with updating my data.
I have User class that contains UserInformation. Theire are linked with one-to-one relation. When I call session.saveOrUpdate() something went wrong. (When I call only update() it dosn't solve the problem)
Data in User table are updated, but in UserInformation isn't , there is created a new row in user_information table with new primmary key.

My User mapping file contains:
Code:
<id name="id" column="user_id" unsaved-value="0">
   <generator class="foreign">
      <param name="property">userInformation</param>
   </generator>
</id>
<one-to-one name="userInformation" class="UserInformation" cascade="all"></one-to-one>
. . .


My UserInformation mapping file contains:
Code:
<id name="id" column="user_information_id" unsaved-value="0">
   <generator class="increment" />
</id>
. . .


Hibernate think that my UserInformation object wasn't save. But it was and it gets an ID.

Some logs:
DEBUG - version unsaved-value strategy NULL
DEBUG - saveOrUpdate() previously saved instance with id: 12
DEBUG - updating [webmail.model.User#12]
DEBUG - processing cascades for: webmail.model.User
DEBUG - cascading to saveOrUpdate()
DEBUG - saveOrUpdate() unsaved instance
DEBUG - fetching initial value: select max(user_information_id) from user_information
DEBUG - first free id: 20


What can I do wrong ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 5:18 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 7:43 am
Posts: 31
Location: León (Spain)
Can you post the java code you are using to save that objects? Are you sure that the UserInformation object inside User object is initialized, has the same id as the object in the DB and is the same object that session.load returns?

Bye.

_________________
Please rate...

Expert on Hibernate errors... I've had them all... :P


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 6:23 am 
Newbie

Joined: Wed Nov 09, 2005 11:03 am
Posts: 5
Hi,

I find my bug.

I create new object of UserInformation and set it to User, so Hibernate find that it have null ID, so he create new row.
I had to call get method and thet change data. It was obviously my missleading.

Sorry to disturb you.

Thanks for repplay :)

Merry Christmas :)


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.