Force Hibernate to read database and not return cached entity
Do the read within a new transaction.
For example:
...
MyDTO myDTO = fetchMyDTOById(daoId);
...
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
private MyDTO fetchMyDTOById(Long dtoId) {
return repository.findById(dtoId);
}
session.refresh(entity)
or entityManager.refresh(entity)
(if you use JPA) will give you fresh data from DB.