posted 16 years ago
Pleasenote: that parent does have many-to-one relationship with child hypothetically, but that is not defined explicitly in mappings.
Only child contains the reference of parent.
now, can someone please tell me, how i can set cascade delete operation in the scenario mentioned above, so that when someone deletes a parent tablle entry with id 1, then all the entries in child table which has foreing key (parent id) as 1 will automatically gets deleted.
Akhil,
It sounds like the parent has a one-to-many relationship to the children, not a many-to-one (otherwise doing a cascade delete would not be good).
If you can, I would actually just create a property in the parent to point to the children and make it private, lazy loaded, and cascade delete. That way it is, for all intents and purposes, invisible and cost-free to everyone except the persistence engine, but when the parent delete happens the children will get automatically deleted as well.