This code
{code:java} // Some comments here Map<String, Object> hints = new HashMap<>(); hints.put(QueryHints.HINT_READONLY, true);
Pupil pupil = em.find(Pupil.class, pupilId, hints);//bug diry checking is on is spite of HINT_READONLY = true pupil.setAge(newAge); {code}
does not turn off dirty checking.
However this works as intended {code:java} CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Pupil> query = criteriaBuilder.createQuery(Pupil.class);
Root<Pupil> from = query.from(Pupil.class); Predicate predicate = criteriaBuilder.equal(from.get(Pupil_.id), id);
query = query.select(from).where(predicate);
Pupil pupil = entityManager.createQuery(query) .setHint(QueryHints.HINT_READONLY, readOnly) .getSingleResult(); {code}
To check it download sample project [https://github.com/stsypanov/spring-data-examples|https://github.com/stsypanov/spring-data-examples] and run *BaseJpaRepositoryImplFindOneReadOnlyTest.testFindOneReadOnlyTrue_useEntityManager_expectValueNotUpdated* |
|