java - Is teneo / hibernate allow me to delete subtree out of the box? -
i have rather complex domain model, implemented in emf , persisted teneo/hibernate/mysql. have subtree of model (subtree in sense of 'containment') no element of subtree referenced outside subtree (only references elements 'contained' in subtree other elements 'contained' in subtree).
i want delete subtree , remove root element collection conatained in. expect work without problems references inside subtree. anyway exceptions mysql foreign key violations encountered. hence deletion fails. deletion process expected work? or teneo/hibernate not clever remove elements in correct order?
the exception message:
com.mysql.jdbc.exceptions.jdbc4.mysqlintegrityconstraintviolationexception: cannot add or update child row: foreign key constraint fails (`ide`.`equip_equipment`, constraint `equip_equipment_usagedomain` foreign key (`component_ud_id`) references `ud_component` (`id`))
update: cascade policies follows:
hibernateproperties.setproperty(persistenceoptions.cascade_policy_on_containment, "all"); hibernateproperties.setproperty(persistenceoptions.cascade_policy_on_non_containment, "refresh,persist,merge"); hibernateproperties.setproperty(persistenceoptions.inheritance_mapping, inheritancetype.single_table.getname()); hibernateproperties.setproperty(persistenceoptions.add_index_for_foreign_key, boolean.true.tostring());
it work if have configured associations cascade delete (remove) operation:
@onetomany(cascade = cascadetype.remove) private set<child> children;
if don't have cascade, removing parent entity remove specific entity, , of course since children have foreign key parent, you'll constraint violation exception.
Comments
Post a Comment