-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria, integer and like
PostPosted: Mon Dec 07, 2009 8:44 am 
Newbie

Joined: Mon Dec 07, 2009 8:36 am
Posts: 1
Hi there,

I'm trying to build a cirteria with a like restriction. The entity property is of type "Decimal" if I try this

Code:
session.createQuery("from P1 where id like :id").setString("id", "%"+s+"%")


this will work, sadly this is a hql query. My criteria looks like this

Code:
return sessionFactory.getCurrentSession().createCriteria(P1.class).add(Restrictions.like("pnr", "%" + s + "%")).list()


this isn't the whole cirteria, there are some more restrictions on it. Anyway with this I only recieve a ClassCastException

Code:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
        at org.hibernate.type.IntegerType.set(IntegerType.java:64)
        at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
        at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
        at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1728)
        at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1699)
        at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1589)
        at org.hibernate.loader.Loader.doQuery(Loader.java:696)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
        at org.hibernate.loader.Loader.doList(Loader.java:2228)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
        at org.hibernate.loader.Loader.list(Loader.java:2120)


Why is this handled so different?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.