In our application we have many native queries (usually, overall when we need to perform some JOIN, LEFT JOIN or FROM clauses using a view on the fly). Moreover, many queries are repeated in many EJBs but the only things they change are some conditions in the WHERE-clause. Obviously, we would like to avoid repeating all those native queries only to change some silly filtering parameters in the end, so it is possible using Hibernate EntityManager to add a WHERE-clause dynamically with some conditions?
I know that with entities and JPQL we can use first CriteriaBuilder
then CriteriaQuery<T>
and finally, by adding some Predicate
, we get a fully built TypedQuery<T>
to execute. But, can we get the same goal using NATIVE queries?