-->
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.  [ 8 posts ] 
Author Message
 Post subject: Entity history - Logical Delete Pattern ??
PostPosted: Wed Oct 08, 2003 7:57 pm 
Newbie

Joined: Wed Oct 08, 2003 7:42 pm
Posts: 18
I am looking for a way to track an entity after removal. I am sure that this is a common situation. A couple of ways that we are considering are logical deletes or history tables.

The Customer/Order/Product situation (http://www.hibernate.org/hib_docs/refer ... xamples-s2)
would encounter this problem. What if you wanted to delete Customer or LineItem that was present in an Order but needed to keep the Order (and its Customer and Lineitem information) for history/reporting purposes.

Is there any pattern or solution to this problem?


The only information I could find was the following, but it only seems to handle part of the problem.

[color=blue]... "neat feature: class level WHERE. This allows for example implementing logical delete (delete using a flag) by having hibernate append


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 9:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
We use something similiar, although we do not utilize the "where" attribute of the hibernate mapping for it.

Basically a bunch of our tables have a column named "active_flg" where true (1) indicates the record is still active and false (0) indicates it is no longer active. So none of these records ever gets deleted. Instead its active_flg column simply gets updated to false.

Then when we build select lists or pick lists we simply filter out all the non-active records for display. Thus they cannot be used for new associations, but old association will not break.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2003 2:24 am 
Newbie

Joined: Wed Oct 08, 2003 7:42 pm
Posts: 18
Thanks for the reply steve.

I was wondering how you tackled cascading. So where I would normally cascade a delete I need to cascade a logical delete (updating children to also be flagged)?

Also, were there any limitations or other problems with this approach?
Thanks again,
Scott Buckham


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2003 7:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
I was wondering how you tackled cascading

We did not implement cascading logical deletes as our domain model is not set up that way. The entities eligible for logical deletion in our system are solely reference/lookup type entities. Major entities, where cascading any logical deletes would be necessary, are not deletable (logically or physically) due to legal restrictions.

Quote:
Also, were there any limitations or other problems with this approach?

Just the typical ones involved in this approach. The biggest is database clutter.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 5:04 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 11:36 am
Posts: 46
Location: Rennes, France
Version : Hibernate 2.1.8

Hi,

I try to use the same logical delete pattern. I succeded to set up the flag when deleting an object, by setting a new class Persister whose delete manegement methods have been modified to update instead of deleting data.
The delete may occur depending on the context, so I use a ThreadLocal to give the contextual information to the Persister.

For the retrieval of the data, the solution is to add systematically the where clause: "my_delete_flag != 1". That's the point.

The Select clause is nor dynamically nor statically extensible. There is no factory for it, and many parts of the code use the "new Select()" statement.

The solution might have been to filter data when querying. That's not sufficient, by example for the lazy-loading use. In this case, you cannot dynamically add filters...

I doubt I'm alone to deal with this kind of problem. Any help would be welcome.

Yann


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 5:29 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 11:36 am
Posts: 46
Location: Rennes, France
Note that Hibernate 3 filters may help me, but i use the 2.1.8 release...

Is there a way to add a where clause to ?

I tried to recode some parts of the persister and loaders, but some static methods cannot be inherited (EntityLoader.whereString() method), without success.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 5:33 am 
Newbie

Joined: Fri Aug 12, 2005 3:55 am
Posts: 11
Hello.
In the enterprise projects, if you need to save history, you must set special flag to 'off' instead of removal data. It is the main statement in busines: the data never must be deleted. However, if you do not need full history, it's useful to delete record and create log entry in other table. That logs can be deleted after some time. You can automaticaly create logs when delete object in the implementation of org.hibernate.Interceptor.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 5:39 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 11:36 am
Posts: 46
Location: Rennes, France
Thanks for the answer. The point is: my application is deployed in several sites and, on 1 site, I have to use the logical deletes (i like to call them "soft deletes").


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