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: Determining object state for persistence
PostPosted: Thu Oct 05, 2006 10:28 am 
Newbie

Joined: Tue Feb 14, 2006 2:40 pm
Posts: 9
Location: Toronto
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


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.