there's method that creates JPA query like this
String queryString = "SELECT i FROM Item i";
if (null != search) {
queryString += " WHERE i.name LIKE :pattern";
}
TypedQuery<Item> query = entityManager.createQuery(queryString, Item.class);
if (null != search) {
query.setParameter("pattern", "%" + search + "%");
}
and there's 2 checks if query needs to have optional search field (if null != search)
what's most common way to avoid that repeat?
With single parameter there could be 2 named queries, or probably Criteria API allows to avoid that (because there is no query string), but is there other ways?