I'm using the JPA CriteriaBuilder to select entities of type MyEntity
from a MySQL db as follows:
String regExp = "(abc|def)"
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery query = cb.createQuery( MyEntity.class );
root = query.from( MyEntity.class );
predicates = new ArrayList<Predicate>();
predicates.add( cb.like( root.<String>get( "name" ), regExp ) );
Thus, the query result should contain any entity where the name
value matches the given regExp. But the result list is always empty.
Changing the regExp to /(abc|def)/g
has no effect, neither does adding the wildcard %
How to make the pattern matching work?
Alternatively: How can I use native MySQL REGEXP together with the CriteriaBuilder?