-->
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.  [ 7 posts ] 
Author Message
 Post subject: Logical delete - delete flag
PostPosted: Wed Mar 29, 2006 12:43 pm 
Newbie

Joined: Wed Mar 29, 2006 12:32 pm
Posts: 1
Hi

Right now I am working on a project and we are using hibernate. Our company policies don't allow doing a "hard delete" and we only use logical delete.

Logical delete works like this. We have a flag on every table called is_deleted, then we map it to hibernate via yes_no type and what we are doing is the following:
-When a user deletes a record we updated is logical delete to false
-Every select or fetch to the database uses as a restrictions the logical delete to only bring "real data".

What I was wondering is if any of you know how can we automate this process...

How can we change hibernate to allow us to change the behavior of delete and get?

It would be a nice feature to add to hibernate a parameter in the mapping and tell what column is the logical delete so we can then hibernate normally.

In every financial or government related or money related project I have been working we don't use real deletes to the DB.

If anyone knows a way around in hibernate to implement this behavior I would greatly appreciate it

And post your opinions or comments about this!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 1:18 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Both requests (change what delete does, and only retrieve not-deleted rows) can be implemented using hibernate's event system. You'll need to implement a standard interface across all deletable objects so that in your even handlers you can cast your object to it, allowing you to access the isDeleted and setDeleted attributes.

You can also use DB triggers to handle the deleting part of things.

The onDelete event handling might be tricky (haven't really thought about it), so an alternative would be to write your own session object, which would wrap/delegate to a real session object. All methods would pass straight through to the real session, except for delete. That would check instanceof LogicalDeletable (or whatever), if false drop through to real delete, otherwise call setDeleted(true) then update that object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 12:48 pm 
Newbie

Joined: Wed May 12, 2004 10:24 am
Posts: 11
Has anyone else taken a whack at this? I'm in the middle of implementing something similar at the moment.

The largest issue (to me) is how to deal with cascading the delete down into the collection changes.

If I implement a listener for DeleteEvent, I can only change the event being triggered for the entire object graph from delete to update.

If I implement a listener for PreDeleteEvent, vetoing the delete operation means processing the graph stops.

Any ideas on how to cascade the logical delete down thru?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 12:00 pm 
Newbie

Joined: Wed May 12, 2004 10:24 am
Posts: 11
FYI for anyone else who is implementing this in their application...

I ended up having to hook into the hibernate meta-data and manage this on my own..

pseudocode....
Code:

SoftDelete extends DefaultDeleteEventListener {
  onDelete (DeleteEvent event) {
    if (event.getObject should be soft deleted) {
       if event has collections
          loop thru properties
            if property is collection && marked with delete cascade
              loop thru collection and delete each element
       mark event.getObject as deleted and update
    } else
       super.onDelete(event)
  }
}



this is definitely a hack but there doesn't appear to be a way to soft delete and still cascasde that delete down thru collections. it would be very nice to have a way of doing this at a finer level with the event architecture (if anyone out there is listening). i would think many applications have a business requirement for this type of functionality.


Top
 Profile  
 
 Post subject: Me too...very interested
PostPosted: Tue Jun 06, 2006 5:19 am 
Newbie

Joined: Fri Feb 24, 2006 4:17 am
Posts: 4
I just wanted to throw my name out there as another person who's interested in this as well.

Many big companies, like the one I work for, have a no-delete policy in place and force you to implement using a deleted_flag column on a table. As adoption of hibernate goes into the mainstream this will become more and more of an issue.

For example, imagine a place like Amazon.com trying to use hibernate. I imagine they don't delete any data as it's all very sensitive customer data.

Anyone from the hibernate team watching this thread?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 4:39 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
Anybody posted this as a feature request in JIRA?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 6:56 am 
Newbie

Joined: Thu Nov 10, 2005 6:05 am
Posts: 16
Is there any news about this feature?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.