Hello,
can you give me a "cookbook recipe" for implementing a ternary association with support for cascading deletion when an object at any of its ends is deleted?
Here is what I want to achieve (based on the brief example from the manual):
1. The entities "employer" and "employee" are associated with a "contract", which might include additional attributes.
2. If an employer is deleted, all of her contracts are also deleted (cascade). The deletion should, if possible (?), occur by issuing an SQL statement like "delete from contract where employerID=?", rather than by loading up each contract and issuing "delete from contract where id=?" in a loop.
3. Likewise, if an employee is deleted, all of her contracts are deleted. By analogy, "delete from contract where employeeID=?" should do the job.
Hibernate experts, how would you suggest implementing this kind of relationship? I tried with two many-to-one mappings, but that approach seems to force me to manage the deletion of dependent "contracts" myself, and the deletions then occur by contract id.
While deleting contracts by cascade might sound silly, there are other situations where the described behavior is needed. If you think otherwise, I would be interested what alternatives there are on the conceptual level.
Best regards -
Jan Ploski
|