Hi,
I have a 'service' object which is associated with a set of 'availabilty levels' objects in a many-to-many mapping:
Code:
<set name="availabilityLevels" lazy="false" table="AVAILABILITY_LEVEL" inverse="false" cascade="all" sort="unsorted">
<key column="SERVICE_FK"/>
<many-to-many class="com...AvailabilityLevel" column="AVAILABILITY_LEVEL_FK" outer-join="auto"/>
</set>
The following code causes the
association between the requested service (identified by PK) and its applicable availability levels to be deleted:
Code:
public Service findServiceByKey(String key) {
Service service = null;
try {
Session session = getSession(); // retrieve a session maintained by ThreadLocal
Service service = (Service) session.load(Service.class, key); // load the service
session.evict(service); // evict it from the session - this causes the associations to be deleted!
}
catch (HibernateException he) {
...
}
return service;
}
After this method has been invoked and the transaction in which it was participating has succesfully completed, the associations are gone! Removing the call to evict the object from the session fixes this problem (i.e. the service <-> availability level assocations are maintained), but I'd really like to understand
why evicting the service object causes this problem (before I start coding a work-around).
Cheers,
James.