Hibernate version: 2.1.2
Oracle 9i release 2
I have to rewrite a large (100s) number of HQL queries in a project.
These all use a number of possible query values.
eg:
from dataStore as db1, datastore2 as db2
where
db.label = 'some string' and
db.label2 = 'some string as well' and
(db.id = anID or
db.id = anotherID or
db.id = a3rdID) and
db2.label = 'string'and
db2.id = ID4
...
you get the picture.
the problem:
any or all of these values(string and int) may be specified or empty...
at the moment they are using stringbuffer and appending the HQL as is neccessary.
however, the client wants to change to named variables.
and make it all clearer
I can use the standard '%' wildcard in a ternary statement for the string values...
Query q;
String qS = new String("from db where db.code = :code")
q = session.createQuery (qS);
q.setString("code",(code.length() >=1 ? code : "%" ));
but I am searching for a way to do the same with numbers...
The major problem I am running into is putting a numerical wildcard into the named parameter. I can't find one.
I have looked everywhere to no avail, so now I am asking here.
Any Ideas will be most welcome.
Thanks.
|