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.