I'm currently trying to implement the function "Load all X where X.name contains y" using a Ms SQL-Server and the Panache-Repositories. I know the SQL-Query "SELECT * FROM X WHERE X.name LIKE '%0y%'" works, but I can't get it to work using the Panache-Query. I've tried
@ApplicationScoped
public class XRepository implements PanacheRepository<X> {
public List<X> listWhereLike(String like) {
return list("name like ?1", "%" + like + "%");
}
public List<X> listWhereLike(String like) {
return list("name like %?1%", like);
}
public List<X> listWhereLike(String like) {
return list("contains(name, ?1)", like);
}
}
but none of them work. They either throw an exception because of the unexpected character '%' or '(' or they simply return an empty list.
What am I missing?
This is the solution , you just need to put the pattern in a String before adding it to the query;