This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes identifier of an instance altered Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "identifier of an instance altered" Watch "identifier of an instance altered" New topic
Author

identifier of an instance altered

Rachel George
Greenhorn

Joined: May 03, 2007
Posts: 1
I have a Person Class.to tht i'm setting some vales which gets saved in my database through hibernate.
then i used Criteria to load those values.it did perfectly fine.
then i gave person.setId(5) which was 4 earlier and then session.saveOrUpdate(person)
it's giving me error as
org.hibernate.HibernateException: identifier of an instance of Person was altered from 4 to 5

Why is it like that?I'm new to hibernate...

Regards
Rachel
saranga rao
Ranch Hand

Joined: Apr 24, 2007
Posts: 49
if the id is update existing state has a non-null id
if the id is save existing state has null id..

or may be You don't have the priviledges to alter the table

instead you can use update();
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Updating an object and changing the id is not really a valid thing to do in relational databases. The id uniquely identifies a record, if you change it it is analagous to deleting a record and inserting a new one. So, Hibernate will complain if you try to do this.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
saranga rao
Ranch Hand

Joined: Apr 24, 2007
Posts: 49
dynamic-update: If true, then when Hibernate updates a row in the database for a class
attribute that has changed, it generates an UPDATE SQL statement at runtime during the
update() method call on the session and only include the columns of the table that have been
updated. This is an optional attribute; the default is false.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: identifier of an instance altered