Home:ALL Converter>Not able to Delete a record from Parent table having child records even after having Cascade All enabled

Not able to Delete a record from Parent table having child records even after having Cascade All enabled

Ask Time:2018-05-09T18:10:56         Author:Amandeep Singh

Json Formatter

I have a table Department with one to many mapping to Employee table and having cascade type as all.

@OneToMany(mappedBy="department",orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @Fetch(FetchMode.JOIN)
    private List<Employee> emp; 

In database , the child table(Employee) is having this constraint on foreign Key enter image description here


When Iam deleting a record from Department Table in Java Code , Using Hibernate *Delete Function with a Primary key as parameter,*it is Deleting the record from Department table as well as deleting all associated records to it in Employee Table. When Iam running below query (Dep_ref is not primaryKey)

delete from Department where Dep_ref= 99999;

So it should delete all records from Department Table, and associated records in Employee table. But,Iam getting below error.

SQL Error: ORA-02292: integrity constraint violated - child record found 02292. 00000 - "integrity constraint (%s.%s) violated - child record found" *Cause: attempted to delete a parent key value that had a foreign dependency. *Action: delete dependencies first then parent or disable constraint.

Can anyone Please Help me out to Fix this issue.

Author:Amandeep Singh,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50250775/not-able-to-delete-a-record-from-parent-table-having-child-records-even-after-ha
yy