I've just started evaluating Hibernate for use with a legacy database, and have a situation where the DBA has used a somewhat unusual scheme:
- Records are never actually deleted from a table
- Instead, they have a "state" field that indicates if they are deleted
From what I've read, I've seen no obvious way to model this using Hibernate.
One idea I had was to implement the onDelete callback within the object to somehow update the record instead of deleting it. In the mapping file for the object type, I would supply a condition (in the class tag's "where" attribute) that only records in an undeleted state would be fetched.
This seems like it could have repercussions re child objects, however. Cancelling the delete from the onDelete callback might stop child objects from being called, or from being removed from a parent's collection.
Am I missing something obvious? I've seen this scheme before, once using dates to indicate that a record had "expired," so it can't be that unique.
Thanks!
|