All my tables have a column 'status' which can be set to DELETED - since a cannot for some purposes erase the entries from the db.
My approach is when i read objects with hibernate from the database i always specify a where "status!=deleted" clause. this works fine specialy for collections which are read from association-tables e.g. User has n Groups.
User.getGroups() only retrieves the Groups from the table user2group (userId,groupId,status) with status != DELTED.
To set the status to DELETE i have a class UserGroupRelation which just reperesents a sinlge row a the mentioned table.
The problem which now arises when i try to remove a group from a user.
Code:
UserGroupRelation r = ....
r.setStatus(deleted);
User u = r.getUser();
Group g = r.getGroup();
// this is needed by hibernate but unfortunalty it will physically remove the relation from the database
u.getGroups().remove(g);
How can i prevent the phy.delete??
Or is the approach kind of uncommon, stupid??
Is there a best-practice-method to the whole "delete by flag" problem?
Thanks in advance
Jens Zastrow