Hibernate version: 3.2.5
If I use the following HQL query everything works like a charm:
Code:
Query query = session.createQuery("from Employment where since > :now");
query.setDate("now", new Date() );
query.setCacheable(true);
Cache statistics:
Code:
org.hibernate.stat.StatisticsImpl - query cache puts: 1
org.hibernate.stat.StatisticsImpl - query cache hits: 3
org.hibernate.stat.StatisticsImpl - query cache misses: 1
Generated SQL:
Code:
select
employment0_.id as id5_,
employment0_.companyName as companyN2_5_,
employment0_.since as since5_,
employment0_.till as till5_
from
Employment employment0_
where
employment0_.since>?
But with the criteria API it won't work:
Code:
Criteria criteria = session.createCriteria(Employment.class);
criteria.add(Restrictions.gt("since", new Date()));
criteria.setCacheable(true);
Cache statistics:
Code:
org.hibernate.stat.StatisticsImpl - query cache puts: 4
org.hibernate.stat.StatisticsImpl - query cache hits: 0
org.hibernate.stat.StatisticsImpl - query cache misses: 4
Generated SQL:
Code:
select
this_.id as id5_0_,
this_.companyName as companyN2_5_0_,
this_.since as since5_0_,
this_.till as till5_0_
from
Employment this_
where
this_.since>?
Is it a bug or am I missing something ?