Skip to content

Instantly share code, notes, and snippets.

@bocato
Last active November 7, 2016 13:15
Show Gist options
  • Save bocato/7a468441b476e762d1a9 to your computer and use it in GitHub Desktop.
Save bocato/7a468441b476e762d1a9 to your computer and use it in GitHub Desktop.
Fugindo do Erro de Lazy no Hibernate
@Override
public List<Task> findAllByProcess(Long processId) throws SGPIException {
/**
* Como ProcessDefinition é um relacionamento com fetchType=LAZY, se eu passar uma lista e
* depois tentar pedir algum parametro desta lista ele será obrigado
* a instanciar o objeto, portanto passa a ser acessível e não vai
* mais dar erro de LAZY.
* */
List<Task> tasks = taskRepository.findAllByProcess(processId);
for (Task task : tasks) {
task.getProcessDefinition().getIdProcessDefinition();
}
return tasks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment