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]