-->
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: How to delete one criteria from DetachedCriteria?
PostPosted: Tue Aug 04, 2009 6:33 pm 
Newbie

Joined: Mon May 11, 2009 3:15 pm
Posts: 4
I have DetachedCriteria object look like this.

DetachedCriteria dc = DetachedCriteria.forClass(Car.class)
.add(Restrictions.eq("isWork", true))
.add(Restrictions.eq("isRed", false))
.add(Restrictions.eq("isBlue", true))
;

Supose I want to delete one of Restriction for example the second one.
Is any way to do this automaticly?


Top
 Profile  
 
 Post subject: Re: How to delete one criteria from DetachedCriteria?
PostPosted: Mon Aug 10, 2009 7:08 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Just create a method that takes boolean parameters, and pass the appropriate boolean parameters in, depending upon which restrictions you would like to incorporate.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: How to delete one criteria from DetachedCriteria?
PostPosted: Mon Aug 10, 2009 10:42 am 
Newbie

Joined: Mon May 11, 2009 3:15 pm
Posts: 4
I use spring and SimpleFormController.
DetachedCriteria is used in Command object. When user want to see the page in first time ( for example GET /result.htm )
my dc object have to have some default restrictions ( Im adding this in constructor of the command object and when spring load this path "he" not call any set methods, only constructor is called so this is only one place where this default restriction can be add. )
but when he GET /result.htm?param=xx&param2=yy
( so in this moment the default constructor add default restriction and call serParam, setParam2 methods )

I can pass for example GET /result.htm?addDefaultRestriction=true
or GET /result.htm?addDefaultRestriction=false&param=xx&param2=yy
and in my SimpleFormController command object

setAddDefaultRestriction(boolean b) {
this.dc.add(Restriction....);
}

but this is ugly is'nt it?
I mean this is not friendly for user to read address in browser. superhost.pl/excelentpath?andUglyDefaultParam=true


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.