Fixed
Details
Assignee
Nathan XuNathan XuReporter
Sergei TsypanovSergei TsypanovLabels
Components
Fix versions
Priority
Critical
Details
Details
Assignee
Nathan Xu
Nathan XuReporter
Sergei Tsypanov
Sergei TsypanovLabels
Components
Fix versions
Priority
Created August 30, 2017 at 8:09 PM
Updated February 7, 2020 at 5:20 PM
Resolved January 6, 2020 at 2:59 PM
This code
// 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);
does not turn off dirty checking.
However this works as intended
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();
To check it download sample project https://github.com/stsypanov/spring-data-examples and run BaseJpaRepositoryImplFindOneReadOnlyTest.testFindOneReadOnlyTrue_useEntityManager_expectValueNotUpdated