Hi there,
my task is to delete an entity B that holds a many-to-one reference to an entity A as soon as the referenced entity A is deleted -- basically a cascade delete in the DB. The association is unidirectional and entity A does not "know" about entity B.
Java code:
Code:
public abstract class RootEntity {
private Long id;
...
public Long getId() { ... }
}
public class EntityA extends RootEntity {
...
}
public class Entity B extends RootEntity {
protected EntityA;
...
public EntityA getEntityA() { ... }
}
Hibernate mapping:
Code:
<hibernate-mapping ...>
<class name="RootEntity" abstract="true" ...>
<id name="id" type="long">
<generator class="native" />
</id>
...
<subclass name="EntityA" extends="RootEntity">
<join table="entitya">
<key column="id" foreign-key="FK_A_Root" />
...
</join>
</subclass>
<subclass name="EntityB" extends="RootEntity">
<join table="entityb">
<key column="id" foreign-key="FK_B_Root" />
...
<many-to-one name="entitya" column="entitya_id"
class="EntityA" foreign-key="FK_B_A"
not-null="true" update="false" />
</join>
</subclass>
...
</class>
</hibernate-mapping>
The relationship is not unique, there may be several instances of EntityB referencing the same EntityA.
I want to achieve that the foreign key FK_B_A is marked ON DELETE CASCADE. How do I do that?
BTW: It is not intended to make EntityB known to EntityA by adding a reference or a collection of references to it.
CU
Froestel