-->
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: criteria-api: "cannot perform lookups on timestamps&quo
PostPosted: Sun Jan 30, 2005 10:59 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
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?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 4:37 pm 
Newbie

Joined: Fri Aug 27, 2004 9:37 am
Posts: 2
I had (have) the same question.

Although, you can use a org.hibernate.type.CalendarType to cache a query which uses data and time.


Top
 Profile  
 
 Post subject: Joda-Time
PostPosted: Fri Mar 04, 2005 3:05 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
As I am going nuts using javas calander classes I experimented with JODA http://joda-time.sourceforge.net/ and implemented a Hibernate3 UserType for its DateTime class http://l3x.net/imwiki/Wiki.jsp?page=Joda

It looks like this solved it too.


Top
 Profile  
 
 Post subject: Re: cannot perform lookups on timestamps
PostPosted: Wed Feb 08, 2006 6:50 pm 
Newbie

Joined: Fri Apr 15, 2005 7:52 pm
Posts: 13
Hi,

We have the same issue and for now decided against changing all our existing date mappings to a custom defined type due to time constraints. From our perspective the desired hibernate behavior would be that hibernate ignores the cacheable flag on a query containing a date restriction. It's fine if the user won't get the benefit of caching on these queries, but it should not fail later on on the lookup but instead recover from the attempted lookup and disable caching on the query. That would avoid having to generally setCacheable to false inside the query handling for a centralized db broker class. Any thoughts on this? Thanks

_________________
Tired of spam? => http://www.spamino.com


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.