SimpleExpression with Like predicate #2061

Klinton90 opened this Issue Dec 12, 2016 · 1 comment


None yet

1 participant

Klinton90 commented Dec 12, 2016 edited

Is it possible to allow "LIKE" operation on all types of expressions (SimpleExpression) or cast Expression as StringExpression? I tried to make request:

SELECT * FROM table AS t WHERE LIKE "%some%" OR LIKE "%some%";

where name is String and id is Number.
I was investigating a bit, found ambiguity in current implementation. My code:

BooleanBuilder where = _getDefaultPredicateBuilder();
BooleanBuilder whereLike = new BooleanBuilder();
for(String likeField: _likeFields){
    whereLike = whereLike.or(_pathBuilder.getString(likeField).contains(likeValue));

If first element in _likeFields is type of String - request works fine, otherwise it throws InvalidDataAccessApiUsageException.

Thanks for help in advance.

Klinton90 commented Dec 14, 2016 edited

Never mind, I've already found solution, just build Path from Field and providing Predicate via Expression (I just want to implement basic search on multiple fields [aka global search] generically, i.e. I do not want to implement same method for each Repository, so I use custom annotation in Domain to build _likeFields, which is now List<Field>).
You may just want to review strange behavior when I can:

  • use PathBuilder.getString() on any domain field type (probably throw Exception if DomainField is not type of String)
  • can/cannot execute request depending on order of provided fields in example above...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment