-->
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.  [ 4 posts ] 
Author Message
 Post subject: MySQL update problem
PostPosted: Mon Oct 13, 2003 11:14 am 
Newbie

Joined: Mon Oct 13, 2003 11:07 am
Posts: 2
This is fragment of code. Base - MySQL.

...
PointInfo pi4 = (PointInfo)sess.load(PointInfo.class,new Integer(2));
pi4.setDescription("Description");
sess.update(pi4);

sess.flush();
sess.close();


When i do session.flush() i get exception:
net.sf.hibernate.HibernateException: identifier of an instance of PointInfo altered from 2 to 2

Something wrong with it ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2003 3:34 pm 
Newbie

Joined: Tue Oct 07, 2003 2:56 pm
Posts: 13
I believe the only valid time to call sessionA.update(obj) is when the obj has been loaded from a different session, say sessionB. Calling session.flush() will flush your changes to the database. so

Code:
PointInfo pi4 = (PointInfo)sess.load(PointInfo.class,new Integer(2));
pi4.setDescription("Description");

sess.flush();
sess.close();


Should write the differences.

use update in the following situation

Code:
PointInfo pi4 = (PointInfo) sessionA.load(PointInfo.class,new Integer(2));
pi4.setDescription("Description");
sessionA.flush(); sessionA.close();

....

sessionB.update(pi4);
sess.flush();
sess.close();


You would do this between states in a web application for instance where pi4 was loaded on one page and updated on another server interaction.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 3:17 am 
Newbie

Joined: Mon Oct 13, 2003 11:07 am
Posts: 2
I've try 1-st code - i get same exception. May be i need new version of server or JDBC-driver ?
Now it's 4.0.12-nt server and 3.0 Connector/J driver


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 7:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This problem happens when your object returns the wrong java wrapper type from getId(). Make sure you havn't mapped integers as longs, or vice-versa.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.