-->
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: ClassCastException when using Restrictions.like on Integer
PostPosted: Fri Mar 28, 2008 8:06 am 
Newbie

Joined: Fri Mar 28, 2008 7:57 am
Posts: 1
Hibernate version: .2.2.ga


Hi!

I have the need to use a like expression with "%" as a placeholder on a integer column.

The problem is that Hibernate raises a classcastexception, since it is trying to cast the criterion to an integer.

lCriteria.add(
Restrictions.like(
"myIntColumn",
"1%"
)
);

What can I do about this?

TIA

Regards,
Andre


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 28, 2008 8:15 am 
Newbie

Joined: Tue Mar 18, 2008 12:37 pm
Posts: 4
Not sure if that's possible the way you're trying that out.
Another solution would be to use the Restrictions.sqlRestriction criterion, given a proper SQL statement that converts your INT type to a STRING and then applies the LIKE comparison to it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 28, 2008 4:52 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Wildcard search will work on String and will not work on Integer...Converting to String will lead to changes in DB, mapping etc....

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


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.