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.  [ 1 post ] 
Author Message
 Post subject: identifier of an instance [bean] was altered from <x>
PostPosted: Thu Nov 02, 2006 12:39 pm 
Newbie

Joined: Fri Oct 20, 2006 1:50 pm
Posts: 6
I had posted an item about this a week or so ago: http://forum.hibernate.org/viewtopic.php?t=966245&highlight=

In that post, i had a table with an identity key in sql server and a corresponding bean and mapping file. when I would try to save() (or saveOrUpdate() or merge() or persist()), I would get this error:

Quote:
org.hibernate.HibernateException: identifier of an instance of package.ProjectBean was altered from 1 to 0


I assumed the problem related to both Hibernate and SQL Server attempting to set the primary key value. So I changed my code and database schema. Now the primary key field in the database is simply an int, without any identity attributes. The generator in the mapping file for the primary key is increment, not identity. However, I still get the SAME problem. It appears that Hibernate is getting the new primary key value correctly, but in the org.hibernate.event.def.DefaultFlushEntityEventListener.checkId() method call that occurs, it appears that the primary key value for the bean has not been set, so the new key and old key values are not the same and saving is not permitted:

Code:
   if ( persister.canExtractIdOutOfEntity() ) {

         Serializable oid = persister.getIdentifier( object, entityMode );
         if (id==null) {
            throw new AssertionFailure("null id in " + persister.getEntityName() + " entry (don't flush the Session after an exception occurs)");
         }
         if ( !persister.getIdentifierType().isEqual(id, oid, entityMode) ) {
            throw new HibernateException(
                  "identifier of an instance of " +
                  persister.getEntityName() +
                  " was altered from " + id +
                  " to " + oid
               );
         }
      }


I believe that somewhere, Hibernate is not setting the primary key in the bean as it should, and this is causing the problem. As mentioned, this is a VERY basic example and I can't imagine what I am doing wrong. The code to test this is done in an JSP page. I didn't know if that could have anything to do with it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.