The below code triggers a Exception in thread "main" org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.model.entity.WorkflowProcessEntity.workstations, no session or session was closed
error. So I wrapped the method with @Transactional
within a service class and it still throws the error.
WorkstationService workstationService = (WorkstationService) ApplicationContextProvider.getApplicationContext().getBean("workstationService");
for (WorkstationEntity workstationEntity : workstationService.getWorkstations(getEntity())) {
registerWorkstation(new ImpositionWorkstation(workstationEntity));
}
WorkstationService.java
@Transactional(readOnly = true)
public Collection<WorkstationEntity> getWorkstations(WorkflowProcessEntity workflowProcessEntity) {
return workflowProcessEntity.getWorkstations();
}
WorkflowProcessEntity.java
@OneToMany(mappedBy = "workflowProcess")
@JsonIgnore
public Collection<WorkstationEntity> getWorkstations() {
return workstations;
}
How can I query this relationship correctly?