-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to modify criteria object?
PostPosted: Thu Aug 31, 2006 7:21 am 
Newbie

Joined: Thu Aug 31, 2006 7:03 am
Posts: 2
Location: India
Hello,

I am working on Hibernate DetachedCriteria objects to build queries.

I want to know if there is a way to remove an already specified Restriction on a DetachedCrtiteria.

Code:
employeeCriteria.add( Restrictions.eq( "name",  "xyz" ));


I want to remove this restriction. Can this be done?

TIA,
Advait


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 3:50 pm 
Beginner
Beginner

Joined: Thu Aug 19, 2004 2:33 pm
Posts: 30
Location: CA, USA
I don't think so. Download the source code and look at org.hibernate.impl.CriteriaImpl. You can cast your Criteria object to a CriteriaImpl and get further control over it, but I don't see methods for modifying it in the way you want.

What's your reason for modifying it? Are you caching it and trying to reuse it? If so, you may want to store an intermediate object instead such as a list of Restrictions and then just recreate the Criteria as needed.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 12:23 am 
Newbie

Joined: Thu Aug 31, 2006 7:03 am
Posts: 2
Location: India
Thanks for the reply.

As far as need and implementation is concernced, assume that there is a API that dynamically gives me DetachedCriteria object build based on some query parameters. Now what i want is to filter this and remove some of the Restrictions.

I know this might not make any sense, but the intermidiate API we are using is mandatory. And we get control of DetachedCtiteria once this API builds it.

So do you think there is any way to do so. Or else, Are you very much sure that this is not possible? If so i need to think of some alternatives/workaround.

Thanks,
~Advait


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 3:37 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 2:33 pm
Posts: 30
Location: CA, USA
I can't say I'm 100% sure you can't do it, but I don't know a way and the API for Criteria and DetachedCriteria don't have methods for modifying the restrictions you already have added.

I do something similar to what you want to do. In my case I have a web interface and the page is backed by a default criteria with several restrictions in it. The user can then decide to add additional restrictions to the query or remove some of the ones already there. In these cases, I cache a list of the restrictions they want and a list of the columns (projections in hibernate terminology) they want. I then reconstruct the actual Criteria instance with each servlet request that comes in by adding to or removing entries from these lists.


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