Seam hibernate delete orphan problem

596 views Asked by At

Im using an entity Employee and inside that a list of UserMaster is defined

public class EmployeeMaster{
    private String employee_id;
    private String first_name;
    private String last_name;
    private List<UserMaster> userMaster = new ArrayList<UserMaster>();

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "employeeMaster")
    @Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.DELETE_ORPHAN})   
    public  List<UserMaster> getUserMaster() {
        return userMaster;
    }
    public void setUserMaster(List<UserMaster> userMaster) {
        this.userMaster = userMaster;
    }
}

in my method im calling

xsession.saveOrUpdate(employeeMaster);

Here im clearing previous child collection explicitly and add new Child objects

But the delete orphan is not working here .. Only the insert query is running Pls Help

A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity

message is showing in the console

1

There are 1 answers

2
axtavt On BEST ANSWER

It looks like you replaced the collection contained in the loaded entity with setUserMaster().

When collection is configured with DELETE_ORPHAN, you cannot replace the collection this way, you need to modify the existing collection using its own methods.