Hello!
I guess this question might have been asked a lot but I just couldn't find where.
So, I have one-to-many relation between Data and Link (one Data - many Links). I want to ensure that when all the Links that reference a Data are deleted, the Data will be removed as well.
Is there a way to declare such behaviour in Hibernate?
I tried to use callback method on remove of Link and check whether the linked Data still has more Links but I was not able to get the callback method called.
I have the following data model:
LinkBase class
Link extends LinkBase (Joined inheritance) and has a Data
I have the following method in both Link and LinkBase:
Code:
@PreRemove
public void onDelete()
The code that I actually test with is:
Code:
LinkBase base = findById(...);
currentSession.delete(base);
It seems I have 2 questions in this topic and I think I must be missing something really basic for both of them.
Any help is appreciated!
[/code]