Hello together,
I want to create a Criteria Query with a converter (String to Binary) and a bitwise operator. Is this possible with the CriteriaApi? I couldn't find any soution.
Code:
Select * from MyTable
where CONVERT(VARBINARY(4), SUBSTRING(foo, 10, 4), 2) &10= 10
The column foo is a String (varchar in MSSQL).
Substring is no problem:
Code:
Path<String> field = root.get(MyTable_.foo);
Expression<String> expression = cb.substring(field, 10, 4);
In order to convert fields I found following statement:
Code:
ParameterExpression<?> param1 = cb.parameter(String.class, "convertParam1");
cb.function("CONVERT", Byte[].class, param1, expression);
query.setParameter("convertParam1", "VARBINARY");
But there I also get the problem that hibernate includes the parameter param1 with '' e.g. 'VARBINARY' instead VARBINARY
Source:
jpa-criteria-api-function-convert-or-castSo the query is:
Code:
CONVERT('VARBINARY', SUBSTRING(foo, 10, 4))
instead
Code:
CONVERT(VARBINARY, SUBSTRING(foo, 10, 4))