I have Site entity and a set of site domains:
Code:
<class name="Site">
<id column="ID" ...>
<set name="siteDomains" cascade="all" >
<key column="SITE_ID"/>
<one-to-many class="SiteDomain"/>
</set>
</class>
<class name="SiteDomain">
<id name="id"..>
<property name="domain" column="SITE_DOMAIN" type="string" unique="true"/>
</class>
When I need to update site domains from form I use simply:
hibernateTemplate.update(site);
but it violates the unique constraint for SITE_DOMAIN column, because Hibernate tries first to add new row in site domain table. When I try first to delete all site domain collection I get an exception
hibernateTemplate.deleteAll(site.getSiteDomains());
Code:
org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException: deleted object would be re-saved by cascade (remove deleted object from associations)
Any suggestions how to tackle that?