I am facing a weird issue. I have a hierarchy like Manager -> Dao. I have update method in Manager which takes the domain object as input and Id of the entity as param. I am doing dao.findById in manager and then converting domain object to entity object passing it to dao. In dao, I am again doing the findById call in Dao (as update can be called directly from DAO also), now this time hibernate again fetching the data from the DB instead of taking it from persistence context. May someone please help me in this case?
In Manager:
@Override
@Transactional(rollbackFor = Exception.class)
public E update(E entry, ID id) throws ManagerException {
try {
B bean = getDao().findById(id);
bean = convertToEntity(entry, bean);
B newEntity = getDao().update(bean, id);
E newEntry = convertToEntry(newEntity);
return newEntry;
} catch (DaoException de) {
throw new ManagerException(de);
}
}
In DAO:
public T Update(T entity,ID id){
T oldEntity = findById(id);
if (oldEntity == null) {
throw new DaoException(ERPErrorCodes.RECORD_NOT_FOUND);
}
return update(entity, oldEntity, id);
}