CriteriaQuery<Book> query = builder.createQuery(Book.class);
Root<Book> book = query.from(Book.class);
List<Predicate> predicates = new ArrayList<Predicate>();
if (StringUtils.hasText(bookSearchCriteria.getTitle())) {
String title = bookSearchCriteria.getTitle().toUpperCase();
predicates.add(builder.like(builder.upper(book.<String> get("title")), "%" + title + "%"));
}
if (bookSearchCriteria.getCategory() != null) {
Category category = this.entityManager.find(Category.class, bookSearchCriteria.getCategory().getId());
predicates.add(builder.equal(book.<Category> get("category"), category));