| 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
 
 
 |