We're updating the issue view to help you get more done. 

em.find() ignores QueryHints.HINT_READONLY

Description

This code

1 2 3 4 5 6 // 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

1 2 3 4 5 6 7 8 9 10 11 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

Environment

None

Status

Assignee

Unassigned

Reporter

Sergei Tsypanov

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.10

Priority

Critical