QueryDSL Like operation on Number
Question
I have to search a number-field with wildcards. The corresponding JQPL query would be like this:
SELECT e From Entity e where e.personNumber LIKE :numberPattern
numberPattern is a String like this: "1??2" and e.personNumber is a Number on the Database (H2).
If i run this with JQPL it's no Problem at all but I can't put it into a queryDSL query.
when I try to
andBuilder.and(entity.personNumber.stringValue().like(numberPattern)
I get a
org.apache.openjpa.persistence.ArgumentException: "str (" bei Zeichen 7 gefunden, erwartet wurde jedoch ["(", "+", ...
If i try to do it like this:
Constant<String> constant = (Constant<String>) Expressions.constant(personNummer);
PredicateOperation predicateOperation = new PredicateOperation(Ops.LIKE, entity.personNumber, Expressions.constant(constant));
the result will be a
Data conversion error converting "1*"; SQL statement:
Caused by: java.lang.NumberFormatException: For input string: "1*"
So, is there a way to have a like operation on an number field with queryDSL?
Solution
Did you try this
PredicateOperation predicateOperation = new PredicateOperation(Ops.LIKE,
entity.personNumber, Expressions.constant("1%"));
I will see why the stringValue() expression doesn't work for OpenJPA.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow