-->
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: Expressions and data types - can I just use Strings?
PostPosted: Sun Oct 05, 2003 11:37 am 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
I'm trying to use the QueryByCriteria API to allow users to build dynamic queries. Basically, I'm presenting them with a drop-down that contains all the tables/column that they're able to search on. Then they're presented a drop-down of expressions (i.e. <, >, =, !=) and finally a text box for the value they want to search for.

I noticed that when querying using Expressions, my "value" must be the same type as the property I'm searching on:

Criteria filter = ses.createCriteria(clazz);

if (expression.equals("=")) {
filter.add(Expression.eq(field, Double.valueOf(value)));
}

List results = filter.list();

If I don't do Double.valueOf() when searching on a Double property, I get a ClassCastException. What's the easiest way to dynamically (at run-time) convert the value to the desired property type?

I'm using Hibernate 2.0.2.

Thanks,

Matt


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.