|
I have an object containing a Map<Establishment,StandardSet> where the StandardSet is persisted by the UserType implementation com.cpm.mainsite.usertype.common.StandardSetUserType, which retrieves from and saves to the database correctly.
The problem is, when I change the only property of StandardSet, which is a map itself, by, for example, adding a new element to it, Hibernate doesn't recognize that anything has changed, and thus does not save anything when issuing a session.saveOrUpdate(). Doesn't hibernate call hashcode() or equals() to determine if the object has changed and should be persisted?
I can do a workaround to always create a new StandardSet object whenever changing it's internal map property, but I hope that's not what I need to do.
Thanks in advance for any help.
Lee.
This is the StanardSet class:
public class StandardSet implements Serializable
{
private static final long serialVersionUID = -318752358875938890L;
private Map<Standard,Date> map;
public StandardSet()
{
map = new HashMap<Standard, Date>();
}
public boolean equals(Object obj)
{
if (obj instanceof StandardSet)
{
StandardSet other = (StandardSet)obj;
return (other.map.equals(this.map));
}
return false;
}
public int hashCode()
{
return map.hashCode();
}
public Map<Standard, Date> getMap()
{
return map;
}
}
Hibernate version: 3.1
Mapping document snippet:
<map name="establishmentStandards" table="CATALOG_ITEM_ESTABLISHMENT_STANDARD" cascade="none" lazy="false" batch-size="200" fetch="select">
<key column="CATALOG_ITEM_ID" />
<map-key-many-to-many column="ESTABLISHMENT_ID" class="com.cpm.mainsite.model.common.Establishment"/>
<element type="com.cpm.mainsite.usertype.common.StandardSetUserType">
<column name="STANDARD_IDS" length="1000"/>
</element>
</map>
Name and version of database: MySQL 5.0
|