our API is such that we don't generate setter methods for collections but simply do a getBars().add(new Bar())...
for that we thought we could provide a DirectPropertyAccessor subclass,
that does:
Getter getter = new TxeCollectionDirectGetter( field, clazz, name );
Collection collection = (Collection ) getter.get( target );
collection.clear();
collection.addAll(value);
that did not work. It gave us the error "Don't dereference a collection with cascade="all-deleteorpha..."
so now we are trying to understand exactly what the setter should do:
- Is the idea that the setter should accept a hibernate.PersistentBag instance which is what is passed in public void set(Object target, Object value, SessionFactoryImplementor factory) method?
Just to test this we did implement a setter method as follows:
public List getAggs() {
if (aggs == null) {
aggs = new EObjectContainmentWithInverseEList(OrderEntryElement.class, this,..); }
return aggs;
}
public void setAggs(List list){
aggs = new EObjectContainmentWithInverseEList(OrderEntryElement.class, this, ...);
aggs.addAll(list);
}
with the following Mapping documents:
<class name="orderentry.impl.OrderEntryElementImpl" table="OrderEntryElement">
... <many-to-one name="aggby" class="orderentry.impl.ModelImpl">
<column name="aggby_Model" not-null="true"/>
</many-to-one>
...
</class>
<class name="orderentry.impl.ModelImpl" table="OrderEntryModel">
<id name="modelID" type="long" column="modelID" unsaved-value="0">
<generator class="native"/>
</id>
<bag name="aggs" access="field" inverse = "true" cascade="all-delete-orphan">
<key column="aggby_Model"/>
<one-to-many class="orderentry.impl.ElementImpl"/>
</bag>
</class>
this is not working either. we are now getting "could not set a field value by reflection setter" error.
Are we not allowed to use custom collection class as described above?
thanks in advance,
kagan
|