-->
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: TimestampType.toString java.lang.ClassCastException
PostPosted: Tue Apr 18, 2006 12:39 pm 
Newbie

Joined: Tue Apr 18, 2006 12:33 pm
Posts: 12
Hi folks,

I'm using Hibernate 3.2.0.CR1 with annotations and I get the exception

Code:
java.lang.ClassCastException
Stack Trace:

    * org.hibernate.type.TimestampType.toString(TimestampType.java:55)
    * org.hibernate.type.NullableType.nullSafeSet(NullableType.java:87)
    * org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
    * org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
    * org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
    * org.hibernate.loader.Loader.doQuery(Loader.java:661)
    * org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    * org.hibernate.loader.Loader.doList(Loader.java:2145)
    * org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
    * org.hibernate.loader.Loader.list(Loader.java:2024)
    * org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
    * org.hibernate.impl.SessionImpl.list(SessionImpl.java:1536)
    * org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
[...]


when trying to execute the following code:
Code:
[...]
Criteria criteria;

      if (criteriaMap.containsKey("personId")
            || criteriaMap.containsKey("gender")
            || criteriaMap.containsKey("date"))
      {
         Integer personId = null;
         Integer gender = null;
         String date = null;

         if (criteriaMap.containsKey("personId"))
         {
            personId = (Integer) criteriaMap.get("personId");
            criteriaMap.remove("personId");
         }

         if (criteriaMap.containsKey("gender"))
         {
            gender = (Integer) criteriaMap.get("gender");
            criteriaMap.remove("gender");
         }

         if (criteriaMap.containsKey("date"))
         {
            date = new SimpleDateFormat("yyyy-MM-dd").format(criteriaMap
                  .get("date"));
            criteriaMap.remove("date");
         }

         criteria = getSession().createCriteria(Finding.class).add(
               Restrictions.allEq(criteriaMap));

         if (date != null)
            criteria.add(Restrictions.like("date", date, MatchMode.START));

         if (personId != null)
            criteria.createCriteria("finder").add(
                  Restrictions.eq("id", personId));
[...]

Is this a bug or am I doing something wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 1:57 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
if date is a java field of type Timestamp or Date then instead of using a String in criteria pass a Date object.


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.