-->
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: Problem in updating data
PostPosted: Wed May 30, 2007 12:10 pm 
Newbie

Joined: Tue May 22, 2007 10:02 am
Posts: 7
Hi All

I am displaying data in web form and this data is to be edited and updated.

This is the function i'm using:
public void UpdateUserInfo(User user)
{
session = sm.CreateSession();
session.Update(user);
session.Flush();
}
If i specify the Id of the row to be updated i get the following error:

a different object with the same identifier value was already associated with the session: 10, of class: User

If i dont specify it it get the following:
Unexpected row count: 0; expected: 1

Can anyone help?

Thanks


Top
 Profile  
 
 Post subject: Re: Problem in updating data
PostPosted: Thu May 31, 2007 8:09 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
cam978 wrote:
Hi All

I am displaying data in web form and this data is to be edited and updated.

This is the function i'm using:
public void UpdateUserInfo(User user)
{
session = sm.CreateSession();
session.Update(user);
session.Flush();
}
If i specify the Id of the row to be updated i get the following error:

a different object with the same identifier value was already associated with the session: 10, of class: User

If i dont specify it it get the following:
Unexpected row count: 0; expected: 1

Can anyone help?

Thanks


I'm guessing you aren't quite clear on how a session works.

From the looks of this you are loading the User class in a session and then trying to save it using a different session? Simply keep the session you loaded the object with and after you make your changes call Flush(). The changes will be saved for you automatically, no need to call Update(). Update is used to associate an existing transient object with a session.

When you don't supply the id it isn't finding the record in the database to update, hence you get the other error you stated.

Try the approach I listed above, and let me know if that is not what you are doing, or if my approach does not work for your situation.


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.