Spring 5.3 with Hibernate 5.6:
I am experiencing some performance issues after rewrite/migration from Hibernate Criteria API to JPA CriteriaBuilder for a findByCriteria method that runs ~15k times during startup of my app. Normally, this would take maybe one minute using Criteria API but when I have the JPA code run, all is good until ~9k iterations (which takes about 10 seconds). But starting with ~10k, the execution rate drops to circa 80 queries per second.
Any idea why that is? My code looks like this:
public List<ENTITY> findByCriteria(final Map<String, Object> criteriaMap, final List<String> fields, final Class<ENTITY> entityClass) {
Session session = getSessionFactory().getCurrentSession()
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery cr = cb.createQuery(aliasToBeanClass);
Root root = cr.from(aliasToBeanClass);
List<Predicate> predicates = new ArrayList<>();
// Take info from criteriaMap and create predicates ... some if/else or switch logic
// Take info from fields and create projections
cr.where(cb.and(predicates.toArray(new Predicate[0])));
Query query = session.createQuery(cr);
List<ENTITY> results = query.getResultList();
return results;
}
The statements that are generated using the predicates look like that:
select this_.rowguid as rowguid1_72_0_, this_.tt_path as tt_path2_72_0_, this_.tt_denotation as tt_denot3_72_0_, this_.tt_description as tt_descr4_72_0_, this_.tt_reference as tt_refer5_72_0_, this_.tt_owner as tt_owner6_72_0_, this_.tt_creation_date as tt_creat7_72_0_, this_.tt_creation_user as tt_creat8_72_0_, this_.tt_modification_date as tt_modif9_72_0_, this_.tt_modification_user as tt_modi10_72_0_ from txt_t_text this_ where this_.tt_path=$1 and this_.tt_denotation=$2 and (this_.tt_owner=$3 or this_.tt_owner=$4)