-->
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: Restrictions.or not binding as expected
PostPosted: Mon Oct 12, 2009 4:34 am 
Newbie

Joined: Tue Sep 26, 2006 1:27 am
Posts: 10
Here's a code fragment which builds a criterion array. The interesting part for us is the last "if" block -
I include the rest only for consistence with the log trace:
Code:
Collection<Criterion> criterion_list = new ArrayList<Criterion>();
        if (channel_names != null && !channel_names.isEmpty()) {
            Criterion channel_criterion = getChannelCriterion(channel_names);
            criterion_list.add(channel_criterion);
        } else {
            criterion_list.add(Restrictions.isNotNull("channel_name"));
        }
        if (start_search != null) {
            Criterion start_criterion = Restrictions.ge("starttid", start_search);
            criterion_list.add(start_criterion);
        }
        if (end_search != null) {
            Criterion end_criterion = Restrictions.le("starttid", end_search);
            criterion_list.add(end_criterion);
        }
        if (title_string != null && title_string.trim().length() != 0) {
            Criterion title_criterion = Restrictions.like("titel", MatchMode.ANYWHERE.toMatchString(title_string), MatchMode.ANYWHERE);
            criterion_list.add(title_criterion);
        }
        if (description_string != null && description_string.trim().length() != 0) { 
            Criterion description_criterion1 = Restrictions.like("langomtale1", MatchMode.ANYWHERE.toMatchString(description_string), MatchMode.ANYWHERE);
            Criterion description_criterion2 = Restrictions.like("kortomtale", MatchMode.ANYWHERE.toMatchString(description_string), MatchMode.ANYWHERE);           
            Criterion joint_description_criterion = Restrictions.or(description_criterion1, description_criterion2);
            criterion_list.add(joint_description_criterion);
        }
        Criterion[] criterion_array = (Criterion[]) criterion_list.toArray(new Criterion[]{});
        return findByCriteria(criterion_array);

Now I execute this with the variable "description_string" set to "%". Here is the logging trace
Code:
    where
        this_.channel_name=?
        and this_.starttid>=?
        and this_.starttid<=?
        and (
            this_.langomtale1 like ?
            or this_.kortomtale like ?
        )
TRACE StringType - binding 'tv2oj' to parameter: 1
TRACE TimestampType - binding '2009-10-04 10:05:00' to parameter: 2
TRACE TimestampType - binding '2009-10-04 23:05:00' to parameter: 3
TRACE StringType - binding '%%%%%' to parameter: 5

Parameter 4 is not bound and the query returns no results. My hibernate version is 3.3.0.SP1 (according to the
log).


Top
 Profile  
 
 Post subject: Re: Restrictions.or not binding as expected
PostPosted: Mon Oct 12, 2009 4:46 am 
Newbie

Joined: Tue Sep 26, 2006 1:27 am
Posts: 10
I've simplified the last if block down to
Code:
if (description_string != null && description_string.trim().length() != 0) { 
            Criterion description_criterion1 = Restrictions.like("langomtale1", description_string);             
            criterion_list.add(description_criterion1);
        }

and I still don't get what I expect. The log says
Code:
where
        this_.channel_name=?
        and this_.starttid>=?
        and this_.starttid<=?
        and this_.langomtale1 like ?
TRACE StringType - binding 'tv2oj' to parameter: 1
TRACE TimestampType - binding '2009-10-04 10:05:00' to parameter: 2
TRACE TimestampType - binding '2009-10-04 23:05:00' to parameter: 3
DEBUG AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
DEBUG AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)

Obviously the block is being executed, because the criterion is being added to the query, but the parameter isn't
actually being bound.


Top
 Profile  
 
 Post subject: Re: Restrictions.or not binding as expected
PostPosted: Tue Oct 13, 2009 2:01 am 
Newbie

Joined: Tue Sep 26, 2006 1:27 am
Posts: 10
Could it have something to do with the fact that the parameter which doesn't bind as expected is a Lob while the others are Strings ?


Top
 Profile  
 
 Post subject: Re: Restrictions.or not binding as expected
PostPosted: Fri Nov 13, 2009 4:21 am 
Newbie

Joined: Fri Nov 13, 2009 4:12 am
Posts: 1
-- deleted by user --


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.