-->
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: identifier of an instance ... was altered
PostPosted: Thu Oct 16, 2008 4:02 pm 
Newbie

Joined: Thu Oct 16, 2008 3:27 pm
Posts: 2
Hello,

I am trying to update a field (which is part of a composite key) and I am getting the following exception:

identifier of an instance of com.mshome.EnumEntry was altered from com.mshome.EnumPK@e6013791 to com.mshome.EnumPK@c3b360ee

I have this table "Enum"

Code:
ENUMNAME varchar not null,
ENUMVALUE varchar not null,
CONSTRAINT "ENUM_PK" PRIMARY KEY ("ENUMNAME", "ENUMVALUE")


The pojo:

Code:
@Entity
@Table(name="ENUM")
public class EnumEntry implements Serializable
{
   
   private static final long serialVersionUID = 4534641263402896632L;
   @Id private EnumPK primaryKey = new EnumPK();

   private String enumname;
   private String enumvalue;

       //...enumname & enumvalue get/set

   public boolean equals(Object pOther)
   {
      if (pOther == null) return false;

      if (!(pOther instanceof EnumEntry)) return false;

      EnumEntry other = (EnumEntry) pOther;
      if ((other.getEnumname() == this.getEnumname()) && (other.getEnumvalue() == this.getEnumvalue()))
      {
         return true;
      }
      else
      {
         return false;
      }
   }

   public int hashCode()
   {
      StringBuffer buf = new StringBuffer(getEnumname());
      buf.append('.');
      buf.append(getEnumvalue());
      return new String(buf).hashCode();
   }
   
}

@Embeddable
class EnumPK implements Serializable
{
   
   private static final long serialVersionUID = -2207353386246323824L;

   private String enumname;
   private String enumvalue;
   
   public EnumPK()
   {
   }
   private String enumname;
   private String enumvalue;

       //...enumname & enumvalue get/set

   
   
   public boolean equals(Object pOther)
   {
      if (pOther == null) return false;

      if (!(pOther instanceof EnumPK)) return false;

      EnumPK other = (EnumPK) pOther;
      if ((other.getEnumname() == this.getEnumname()) && (other.getEnumvalue() == this.getEnumvalue()))
      {
         return true;
      }
      else
      {
         return false;
      }
   }

   public int hashCode()
   {
      StringBuffer buf = new StringBuffer(getEnumname());
      buf.append('.');
      buf.append(getEnumvalue());
      return new String(buf).hashCode();
   }
}



The code to update:


Code:
        Session session =  HibernateUtils.getSessionFactory().getCurrentSession();
   Transaction trans = session.beginTransaction();
   Criteria crit =  session.createCriteria(EnumEntry.class);
         crit.add(Restrictions.eq("enumname", enumName));
         crit.add(Restrictions.eq("enumvalue", oldEnumValue));
         List list = crit.list();
         
         if(!list.isEmpty())
         {
            LMSEnumEntry valEntry = (EnumEntry) list.get(0);
            valEntry.setEnumname(enumName);
            valEntry.setEnumvalue(newEnumValue);
            session.update(valEntry);   
         }
        trans.commit();
        session.close();


while attempting commit, I get :identifier of an instance of com.mshome.EnumEntry was altered from com.mshome.EnumPK@e6013791 to com.mshome.EnumPK@c3b360ee


Anyone any idea?

Thanks,
johnny[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 16, 2008 11:47 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
session.update() does not do what you think it does.
Please read the following article

http://hibernar.org/articulos_en/persis ... ethods.php

where I explain it at length.

_________________
Gonzalo Díaz


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.