Hi there,
I am a bit lost. I don't know how to model this right.
Scenario:
* Objects A,B,C
* Object B is a child of A (so A.getBs() and B.getA(), one-to-many)
* Object B reference C (unidirectional assoziation).
Here comes the problem:
Since B reference C, the reference should be set to null if C gots deleted. (SQL: on delete set null).
But I was not able to get things right on first try. So I used a hack using an integer column (primary key of C) without a foreign key constraint. But now it's time to make things right.
So here are the options I can think of:
-Add a second bidirectional mapping between B and C (C is parent) and use onDelete methods on both side to remove the link before either B or C gets deleted (adds the burdon of utilizing the lifecycle, which I think is not such a good option).
-Life with the hack of integer and ensure that if any new C is generated using the same id, things gets corrected (logical link, but this smells that kind of badly that I would like to avoid this).
-Using an unidrectional mapping but again I ran into the problem, how I can create a behaviour like 'on delete set null'.
How is the 'best' way you know, this can be modeled using hibernate?
Thanks
|