[ColdBox 3.8.0] Many-to-one cascade settings on self referencing table

I have this self referencing object, category.cfc

property name=“categoryId” generator=“identity” fieldtype=“id”;
property name=“parent” column=“parentId” fieldtype=“many-to-one” CFC=“category” fkcolumn=“parentId” cascade=“delete”;
property name=“lft” column=“leftId” type=“numeric”;
property name=“rgt” column=“rightId” type=“numeric”;
property name=“name” ormtype=“string” length=“255”;
property name=“description” ormtype=“text”;

If I try to remove a parent

var removed = ormService.deleteById( rc.categoryId );

I got:

Application Execution ExceptionError Type: org.hibernate.exception.ConstraintViolationException : 1451

Error Messages: could not execute update query

How can I set cascade to null to all child elements?

I think you need the inverse = “true”, problem with deleting nested lists is that you need to delete all children before the parent.

I have solved adding this:

property name=“ChildCategory” cfc=“category” fieldtype=“one-to-many”
getter=“true” setter=“false”
singularname=“ChildCategory” lazy=“true”
inverse=“true” cascade=“delete”;

I check if category has child, if true first eliminate all children and then the parent.

Thanks for your help!!