xyz
xyz

Reputation: 2170

Delete rows on the basis of @ManyToMany

public class ClazzA{
    @ManyToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE})
    private List<ClazzB> someData;
}

public class ClazzB{
}

I want to achieve the following functionality:

If someData is removed from the mapping and not used anywhere in clazz_a_some_data (mapping table) , it will automatically deletes the row from table clazz_b.

Is this possible?

Upvotes: 1

Views: 26

Answers (1)

Stefan Steinegger
Stefan Steinegger

Reputation: 64648

This is something you have to implement in your business logic. With cascades, you can only bind the life cycle of an object to the life cycle of another.

For Hibernate to achieve this, it would require something like "persistent garbage collection", which it doesn't have. It would be a performance problem anyway.

Upvotes: 1

Related Questions