Hi everyone,
I'm currently working on a Flex project using Flex 3.0.1 and LCDS 2.6.
On the backend we're using Hibernate (Annotations) to map all of the
biz objects to tables and all of the relationships mapped between the
objects.
Our problem is with cascading deletes. We have a workaround, but want
to make sure it's the best (only?) way to accomplish a cascading
delete or whether there's something fundamental we've missed in our setup.
If I delete the Parent object (below) directly from my IDE it will
cascade fine and delete all of the Child objects in the children
collection:
@Entity
@Table(name = "parent")
public class Parent extends Persistent {
private Long id;
@OneToMany(mappedBy = "parent", targetEntity = Child.class, cascade =
CascadeType.ALL, fetch = FetchType.LAZY)
private List<Child> children;
// getters and setters here
}
But we're noticing some strange behavior when attempting to delete a
Parent object from Flex. What happens is an update is first done on
each of the Child objects in the children collection setting the
Parent object to null, followed by a delete on the Parent. The delete
fails because an error is returned about how the child would be
re-saved on the cascade.
Here are all of the above relationships mapped in the
data-management-config.xml:
<destination id="parent">
<adapter ref="java-dao"/>
<properties>
<use-transactions>true</use-transactions>
<source>com.project.biz.ParentAssembler</source>
<scope>application</scope>
<metadata>
<identity property="id"/>
<one-to-many property="children" destination="child"
lazy="true" cascade="delete-orphan"/>
</metadata>
<network>
<session-timeout>20</session-timeout>
<paging enabled="false" pageSize="10"/>
<throttle-inbound policy="ERROR" max-frequency="500"/>
</network>
<server>
<hibernate-entity>com.project.biz.Parent</hibernate-entity>
<fill-method>
<name>fill</name>
<params>java.util.List</params>
</fill-method>
</server>
</properties>
</destination>
Is it possible to have those Updates on the child objects become
Deletes instead? I tried changing cascade (in the file above) to,
all-delete-orphan, delete, true, and nothing seems to work.
Our workaround for now is to alter the method with signature:
public void updateItem(Object newVersion, Object prevVersion, List
changes)
in the ChildAssembler to check and see if the newVersion object has
the Parent set to null, and if so, we ignore the update.
Then we manually delete the Parent inside the deleteItem method on the
ParentAsssembler with our own HibernateAnnotationConfiguration (which
in turn cascade deletes the child objects in the children collection.)
So far this works, so long as Flex doesn't ever change how it operates
during a delete. I guess we're just looking for the "official" way to
accomplish the same thing, i.e. making a cascading delete work properly.
--Andrew R
U of Iowa