-->
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.  [ 3 posts ] 
Author Message
 Post subject: Classcast exception selection Longid
PostPosted: Thu Oct 14, 2010 5:49 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I'm getting

Code:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
   at org.hibernate.type.LongType.set(LongType.java:65)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:156)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:138)
   at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:67)
   at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:567)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612)
   at org.hibernate.loader.Loader.doQuery(Loader.java:717)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
   at org.hibernate.loader.Loader.doList(Loader.java:2294)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
   at org.hibernate.loader.Loader.list(Loader.java:2167)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)


when I do

Code:
qry = "select oh.id from MyEntity oh where oh.id > :rnd ";
      q = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(qry);
      q.setParameter("rnd", 0);
      q.setMaxResults(100);
      List result = q.list();


The id field in this case is a Long, which hbm2ddl/mysql translates to a BigInt(20).

The resulting rows contain the values 1, 2 and 3.

Using Hibernate 3.5.4.

Seems wrong to me.

Cheers,

Marc


Top
 Profile  
 
 Post subject: Re: Classcast exception selection Longid
PostPosted: Thu Oct 14, 2010 5:56 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
q.setParameter("rnd", 0);


The '0' is an integer and it is probably this that Hibernate complains about. You would need something like:

Code:
q.setParameter("rnd", 0L);


Top
 Profile  
 
 Post subject: Re: Classcast exception selection Longid
PostPosted: Thu Oct 14, 2010 6:25 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
You're right and I'm an idiot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.