I need to create a \"real\" dynamic JPA CriteriaBuilder. I get an Map with the statements. It looks like:
nam
I have always been thinking that creation of solution like that is like reinventing the bicycle. Here https://github.com/sasa7812/jfbdemo is my solution. It was tested on EclipseLink and Hibernate (EclipseLink in production, we used it in several projects for simple cases). Sometimes you just need a quick solution to make a dataTable with sorting and filtering, nothing fancy. It is able to filter and sort on joined fields, and even on collections. Project contains demo on Primefaces showing the abilities of FilterCriteriaBuilder. In the heart of it you just need this:
public List loadFilterBuilder(int first, int pageSize, Map sorts, List argumentFilters, Class extends AbstractEntity> entityClass) {
FilterCriteriaBuilder fcb = new FilterCriteriaBuilder<>(getEntityManager(), (Class) entityClass);
fcb.addFilters(argumentFilters).addOrders(sorts);
Query q = getEntityManager().createQuery(fcb.getQuery());
q.setFirstResult(first);
q.setMaxResults(pageSize);
return q.getResultList();
}
to get the results from database.
I really need someone to tell me that it is usefull and is used somewhere to continue my work on this library.