Apply QueryHints.HINT_READONLY to load operations

Description

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

Activity

Show:

Steve Ebersole January 6, 2020 at 12:52 PM
Edited

Not sure I’d classify this as a bug. They are named QueryHints for a reason. I agree its a worthwhile change, but unless you see documentation somewhere indicating this should be possible I’m re-categorizing this as a RFE

Nathan Xu December 21, 2019 at 10:18 PM

Fixed

Details

Assignee

Reporter

Labels

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