I'm using the Criteria API to create my queries, using Hibernate as the implementation. The database is a MS SQL Server 2014.
In my database I have a string field, which contains numbers as well as strings. I want to compare the numbers to a numerical value. In SQL it would be something like this:
select *
from table
where ISNUMERIC(table.value) and CONVERT(float, table.value) > 5
(Don't quote me on the function names.) There doesn't seem to be a direct way of doing this in Criteria queries, so I tried using the function() method:
Expression<Float> convertedExpression = criteria.function("CONVERT", Float.class, criteria.literal(Float.class), baseExpression);
But this approach gives somewhat unhelpful error messages à la "incorrect syntax near )" or "incorrect syntax near @P1". I'm thinking this is because of the first parameter passed to the method, which must be the type I want to convert to.
Any help getting the CONVERT function to work or an altogether different approach would be greatly appreciated.