Hibernate version:
hiberate3 cvs 2005-01-30
Mapping documents:
annotations
These are the relevant columns of my table:
Code:
public class EventLogDtl implements Serializable {
@Id(generate = GeneratorType.TABLE)
@Column(name="w03_number")
private Long number;
@Column(name="w03_timestamp")
private Date timestamp;
...
As you can see I use a surrogating key and a simple timestamp column.
If I try to query this table and set the cacheable flag
Code:
Criteria crit = session.createCriteria(EventLogDtl.class);
crit.setCacheable(true);
crit.add(Expression.ge("timestamp", startDate));
crit.add(Expression.lt("timestamp", endDate));
List events = crit.list();
I get the following exception
Code:
Caused by: java.lang.UnsupportedOperationException: cannot perform lookups on timestamps
at org.hibernate.type.TimestampType.getHashCode(TimestampType.java:98)
at org.hibernate.cache.QueryKey.hashCode(QueryKey.java:73)
at java.util.HashMap.hash(HashMap.java:264)
at java.util.HashMap.getEntry(HashMap.java:360)
at java.util.LinkedHashMap.get(LinkedHashMap.java:273)
at net.sf.ehcache.store.MemoryStore.get(MemoryStore.java:196)
at net.sf.ehcache.Cache.searchInMemoryStore(Cache.java:523)
at net.sf.ehcache.Cache.get(Cache.java:358)
at org.hibernate.cache.EhCache.get(EhCache.java:110)
at org.hibernate.cache.StandardQueryCache.get(StandardQueryCache.java:74)
at org.hibernate.loader.Loader.list(Loader.java:1316)
at org.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:106)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1603)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:257)
I know, we shouldnt use timestamps as PK-field, but here it is a simple column, but shouldnt it be possible to cache such queries - even if they use timestamps as one of its criterias?