cc-ar-emr / open-o-previous

GNU General Public License v2.0
2 stars 1 forks source link

Upgrade hibernate to latest 5.6.X release #152

Open sebastian-j-ibanez opened 1 month ago

sebastian-j-ibanez commented 1 month ago

We need to upgrade hibernate to the latest version of 5.6.X.

After upgraded to version 5.6.15.Final, we're encountering error: "java.lang.IllegalArgumentException: org.hibernate.QueryException: Legacy-style query parameters (?) are no longer supported; use JPA-style ordinal parameters (e.g., ?1) instead"

Since hibernate 5.6.15 doesn't support "?" as the query parameter, we have to insert number (use JPA-style ordinal parameters) after the "?". The best practice is to insert 1 after the "?" since it is the standards of JPA API, but we need to first refactor all the queries using Hibernate API to JPA API. Below is the example we have now:

import java.util.List;

import javax.persistence.TypedQuery;

import org.apache.commons.lang.time.DateUtils; import org.apache.logging.log4j.Logger; import org.oscarehr.PMmodule.model.AccessType; import org.oscarehr.PMmodule.model.ProgramAccess; import org.oscarehr.util.MiscUtils; import org.oscarehr.util.QueueCache; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.stereotype.Repository;

@Repository public class ProgramAccessDAOImpl implements ProgramAccessDAO {

@PersistenceContext(unitName = "entityManagerFactory")
private EntityManager entityManager;

private static Logger log = MiscUtils.getLogger();

private static QueueCache<Long, List<ProgramAccess>> programAccessListByProgramIdCache = new QueueCache<Long, List<ProgramAccess>>(
        4, 100, DateUtils.MILLIS_PER_HOUR, null);

@SuppressWarnings("unchecked")
@Override
public List<ProgramAccess> getAccessListByProgramId(Long programId) {
    List<ProgramAccess> results = programAccessListByProgramIdCache.get(programId);
    if (results == null) {
        String q = "select pp from ProgramAccess pp where pp.ProgramId=?1";
        TypedQuery<ProgramAccess> query = entityManager.createQuery(q, ProgramAccess.class);
        query.setParameter(1, programId);
        results = query.getResultList();
        if (results != null)
            programAccessListByProgramIdCache.put(programId, results);
    }

    return results;
}

The most ideal solution is to extend the AbstractDaoImpl class, so we won't need to implemented the jpa imports and annotation in the single class. We are going to keep working on this when we move to Hibernate 6, right now we will keep most of the Hibernate queries having "?0" to ensure the application runs properly.

Updates:

sebastian-j-ibanez commented 1 month ago

Context

Additional instructions from @yingbull:

"hibernate; unless one of the update is advised to skip entirely, I would just walk it up patch versions (5.x.##) and minor versions (5.##.xx) till you get to the latest 5.6.x, one at a time, branch and pull request at a time. We are at least now getting close to "common era" so you should be able to find some discussions and migration guides, @garciaerin, @sebastian-j-ibanez.

Just a tip: don't worry about something getting deprecated in the version you are trying to upgrade to: deprecated means it works but they want you to stop. We like works :slightly_smiling_face: given we have a number of upgrades to do, focus on just remediating breaking changes. Fixing deprecated stuff to recommended, unless a security risk, is a luxury for when you are at a supported, up to date version of your framework."

Adding this information here so we have everything in one place.

sebastian-j-ibanez commented 1 month ago

Update

sebastian-j-ibanez commented 2 weeks ago

Daos that need updating

sebastian-j-ibanez commented 2 weeks ago

This issue has been implemented in PR #200.