Hi,
I use Hibernate 3.2.2 GA.
I have a strange comportment with bags in component.
A use a mapping including a component having a bag inside :
<class name="SynchoServiceOrder" table="DS_ORDER" lazy="true">
<component name="periodicity" class="PeriodicityPeriod">
<property column="PERIODICITY_SHIFT"
name="shift"
type="integer"/>
......
<bag name="exceptionsBag" cascade="all-delete-orphan" >
<key column="EXCEPTIONS_PID" />
<one-to-many entity-name="SynchroTimePeriodDeleted" />
</bag>
</component>
</class>
This periodicity is included in a parent object and may be null. In this case, I dont want to store default values from periodicity but null values in the table DS_ORDER. So periodicity object has a method isNullObject() to detect null components :
if ( synchroServiceOrder.getPeriodicity().isNullObject() )
synchroServiceOrder.setPeriodicity(null);
This works fine for all my components except for components having a bag inside.
When I use a merge to save my objects, Hibernate detects that database object has a periodicity (instanciated by Hibernate) and has instanicated an empty exceptionsBag list inside. But in fact this periodicity does not exists, it is an null object in the persisted object. So when I flush the session, I have the error :
A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance SynchoServiceOrder.
The merge has detected that the database object has a list not null and the object to persit has a null list. As the status is not delete, Hibernate supose that the list was set to null explicitly, and return an error.
Hibernate does consider that an empty list is dereferenced if new entity has null list. On a standard mapping, I wouldn't have problem as the parent object of the list exists, but for component, in my context, there is not parent so no possibility to return Collections.EMPTY_LIST if list is null.
The solution I found is to put the bag in the parent object (SynchoServiceOrder) but it can work only for tests, not definitively.
I hope I’ve been clear. Is there a solution for that problem ?
Thanks.
|