Hibernate Hbm many-to-many mapping - delete the other part if don't exists relationship in many-to-many table?

StackOverflow https://stackoverflow.com/questions/15977956

Pergunta

I want to know if there is a way to configure hbm mapping to do something like this: when I delete the owner of a many-to-many relationship, after delete the children at the many-to-many table, delete also the entities in the other part of the relationship if all of them has no more children in the many-to-many table.

I tried to do something like this using the attribute cascade=all in side of the owner but this way delete always the other part, having other more registers in the many-to-many table or not.

Foi útil?

Solução

No, there is nothing out of the box that will delete an entity when you remove the last reference.

You could do that with a trigger, or a delete event listener. In both cases you have to write all the logic.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top