Я пытаюсь внести изменения в мою базу данных MySQL на уровне отношений OneToMany (Swap имеет много SwapWorkflows)
public class Swap {
@OneToMany(cascade=CascadeType.ALL, mappedBy = "swap", fetch = FetchType.LAZY)
private List<SwapWorkFlow> swapWorkFlows;
}
эта транзакция не в сервисе сущностей SWAP, а в запланированном хрон.
@Scheduled(cron = "0,05 * * * * *")
public void opsExpireCron() {
swapWorkflowRepository.findAll().forEach(s->{
if(s.getOrdering()==2 && s.getStatusSwapWorkFlow()==SwapWorkFlowStatus.PENDING){
try {
SwapWorkFlow swapWorkFlowCC = swap.getSwapWorkFlows().stream().filter(swapWorkFlow -> swapWorkFlow.getOrdering() == 1).findFirst().orElse(null);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
в блоке try происходит сбой в строке инициализации swapWorkFlowCC; выдав следующую ошибку:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.intelcia.myintelcia.model.shared.business.Swap.swapWorkFlows, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:587)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:204)
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:566)
at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:135)
at org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:277)
at java.util.Spliterators$IteratorSpliterator.estimateSize(Spliterators.java:1821)