-->
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.  [ 2 posts ] 
Author Message
 Post subject: Same search criteria returns really weird results
PostPosted: Mon May 07, 2012 2:30 pm 
Newbie

Joined: Mon May 07, 2012 2:05 pm
Posts: 2
Hello!

I've got some issues that appears "time-to-time" with Hibernate detached search criteria.
I'm using it with Struts2, saving this detached criteria in HttpsSession map.

When using search criteria I receive normal results most of the times - something about 25 entities (from 2000).
And some times I receive really weird results - Hibernate returns 2000 entities(like filter was not applied at all).

I use filtering using detached crieria using criterions: le, ge with java.util.Date.
Example of code I use:

Code:
public List find(){        //perform initialization
        Date startDate = ...;
        Date endDate = ...;

        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Item.class);
        if(startDate != null)        detachedCriteria.add(Restrictions.ge("startDate", truncateTime(startDate)));
        if(endDate != null)        detachedCriteria.add(Restrictions.le("endDate", truncateTime(endDate)));
        return Collections.unmodifieableList(detachedCriteria.getExecutableCriteria(session).list());
}
...
private Date truncateTime(Date date) {
        Calendar instance = GregorianCalendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.HOUR, 0);
        instance.set(Calendar.MINUTE, 0);
        instance.set(Calendar.SECOND, 0);
        instance.set(Calendar.MILLISECOND, 0);
        return instance.getTime();
}


NB! It's example code, so it could contain some typos. I've provided it just as an example, to help understand what I'm trying to do.

I've spent whole day trying to figure out, what's the problem here.

P.S. Code is running under transaction, that was opened on higher level.

What could be the problem here?
Have anybody seen such kind of weird stuff?


Last edited by diostm on Fri May 18, 2012 6:39 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Same search criteria returns different results time-to-time
PostPosted: Fri May 18, 2012 6:34 am 
Newbie

Joined: Mon May 07, 2012 2:05 pm
Posts: 2
up


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