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?