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: Recommendations Welcome!
PostPosted: Wed Feb 20, 2008 10:47 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
I have some audit fields in the db (create, modify, delete). So I never physically delete a record in the table but flag it as deleted. In the association mapping is there a way to filter out “deleted” records. In other words I don’t even want to pull them from the db. It wouldn’t be efficient.

Do I need to use IInterceptor.OnLoad() somehow

Thanks.


Top
 Profile  
 
 Post subject: Recommendations Welcome!
PostPosted: Thu Feb 21, 2008 4:12 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Are these columns in a separate table ? If not, filter should do the work. Can you post your mapping ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 11:37 am 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
session.filter filters a collection after it has already been pulled from the db. If the record is flagged as deleted I don't want to pull it from the db, or initialise any business entities.

Interceptor.OnLoad happens just before initialisation therefore this is also too late in the life cycle.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 11:42 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
afaik the filter condition is added to the where clause, so the objects should not be pulled from the db. Am I really wrong there ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 11:43 am 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
I guess I should also add that this is a lazy load collection.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 12:07 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can also apply a filter to a collection. I don't know, if lazy loading ignores the filter, but I don't think so. Can you post your mapping ?

If filter don't work for you, you can try adding a "where" clause to your collection mapping:

Code:
<set ....... where="deleted = 0 (or whatever you need here)"> ...</set>


I would prefere the filter because you can enbable and disable it for each session as you need it.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 1:54 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
Sorry I misunderstood what you meant by "filter" (there is a method with the same name). Thanks for the mapping example. I get you now.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 22, 2008 2:57 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You're welcome, hope that helps.

_________________
--Wolfgang


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.