I have following problem, but I can't google sollution.
Let's suppose follwing (just)example. We have a political Party which registers its Members. From point of view of my application this is composition, because it makes no sense to have member without his party. It looks like normal composite one-to-many association, but wait..., the biggest political party in my hypothetical country has 20M Members. And I never want to fetch all this members at once and inicialisation of such a big collection would crash my system.
So I decided to model this situation as many-to-one association where Member see his political Party. Now I can filter and page members and everything is OK. From design point of view is this sollution excelent, but I don't know how to set up automatic cascade delete of all orphan Members when their party is removed from system.
So what I need is to mark somehow this many-to-one association as reversly composite and delete orphan Members when their party is deleted.
How to do this in hibernate mapping?
Example is just hypothetical. I ave quite good experience with this design pattern and I want to use it many times without writing custom code, which would fetch and delete all members before their party is deleted.
|