I received this error:
org.hibernate.MappingException: only inverse one-to-many associations may use on-delete="cascade": src.model.ParteDeItem.materiais
I understand that I can't use on-delete="cascade" on non-inverse one-to-many associations.
As it is show in my mapping below, I am mapping a collection os component (a collection of value objects). So, this association can't be inverse.
How can I indicate that the foreign key of this association is marked as on-delte=cascade in my database, to avoid several deletes sentences when I delete the owner component ?
Code:
<idbag name="materiais" lazy="true" cascade="all-delete-orphan"
table="MATERIAL">
<collection-id type="integer" column="MATERIAL_ID">
<generator class="sequence">
<param name="sequence">MATERIAL_GEN</param>
</generator>
</collection-id>
<key column="PARTE_ITEM_ID" on-delete="cascade" not-null="true" />
<composite-element class="src.model.Material">
<property name="quantidade" />
<many-to-one name="descricaoMaterial"
column="DESCRICAO_MATERIAL_ID" fetch="join" />
</composite-element>
</idbag>