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: Criteria operations on table's columns
PostPosted: Tue Oct 21, 2008 7:17 am 
Newbie

Joined: Tue Oct 21, 2008 7:09 am
Posts: 1
I have the following table:
TABLE
ID Integer,
IMPORTO Integer,
RESIDUO Integer

which is mapped (from Bean) with MyClass:
MyClass{
Integer Id
Integer a
Integer b
}

I need to execute the following query (using CRITERIA API):
SELECT FROM TABLE WHERE IMPORTO - RESIDUO < 10;

which becomes

Criteria criteria = session.createCriteria(MyClass.class);
criteria.add(Restrictions.lt("a", b + 10");
criteria.list();

but i receive this error:

ClassCastException

2008-10-21 10:05:44,080 - DEBUG [Dp] CRITERIA: CriteriaImpl(MyClass:this[][a>b+ 10])

2008-10-21 10:05:44,126 - DEBUG [Servlet] Error:java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

What's wrong with my query?
Can anyone helps me?
Thnx.




Hibernate version 3.2.6


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2008 7:33 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
You are getting this exception as Restriction.lt expects first argument to be name of property and second argument to be value to which this property should be compared.

I don't think this kind of expression can be handled through lt or ltProperty method but you can use sql restriction to get the job done.

_________________
Please rate this post if you find it helpful


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.