-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: "Fake" deletes
PostPosted: Thu Dec 11, 2003 1:30 pm 
Newbie

Joined: Thu Dec 11, 2003 1:12 pm
Posts: 4
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!


Top
 Profile  
 
 Post subject: Subclass EntityPersister and override delete
PostPosted: Thu Dec 11, 2003 2:17 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
I've never done this before, but here's how I would look at doing it. You could subclass EntityPersister and override the delete method to implement your behavior (setting the flag).

In your hibernate mapping file, specify your new persister for the classes that have this behavior with perisister="MyEntityPersister".

HTH,

_________________
- Brian


Top
 Profile  
 
 Post subject: Or instead of overriding delete()...
PostPosted: Thu Dec 11, 2003 2:24 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
Override, generateDeleteString() to give it similar behavior to Update to remove the value from the system.

This will take care of setting it to look like it's removed.

The part where you'll need to only pull back (non deleted objects will be trickier). I'll have to refer to the other Hibernate guys for this one.

There are several classes where code is selected. You might only need to need to override the generateSelectString() since updating "deleted" rows won't hurt you as long as the delete field isn't updated. I can't say for certain.

Maybe the other guys have some ideas...

_________________
- Brian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.