percussion / percussioncms

Percussion CMS - Content Management System
https://percussioncmshelp.intsof.com/percussioncms
Apache License 2.0
10 stars 9 forks source link

WARN [deprecation] HHH90000022: Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead #558

Open natechadwick opened 2 years ago

natechadwick commented 2 years ago

The old hibernate Criteria query has been deprecated and is removed in hibernate 6.0 the next version. We need to update all of the places that we are using the old Criteria query to use the new JPA style query.

Old Example:

Session session = getSession();
        List<PSIntegrityStatus> results = new ArrayList<>();

        Criteria crit = session.createCriteria(PSIntegrityStatus.class);
        if (status != null)
            crit.add(Restrictions.eq("status", status));
        crit.addOrder(Order.desc("startTime"));
        results = crit.list();

        return results;

Fixed Code:

Session session = getSession();

        CriteriaBuilder builder = session.getCriteriaBuilder();
        CriteriaQuery<PSIntegrityStatus> criteria = builder.createQuery(PSIntegrityStatus.class);
        Root<PSIntegrityStatus> critRoot = criteria.from(PSIntegrityStatus.class);

        if (status != null)
            criteria.where(builder.equal(critRoot.get("status"), status));

        criteria.orderBy(builder.desc(critRoot.get("startTime")));

        return entityManager
                .createQuery(criteria)
                .getResultList();
natechadwick commented 10 months ago

This needs broken down as it is used all over the place.