我在 Wildfly 9.0.1 中使用 java 批处理 (jsr-352)。对实体的惰性字段进行步进(基于块)访问的处理器。当处理器想要获取惰性字段时,我给出LazyInitializationException
. 当我在 wildfly 11.0.0.Alpha1 上运行它时,一切正常。在 wildfly 9.0.1 中,当我使用存储库获取此字段时,没有问题。我怎样才能使用存储库做到这一点?
读者:
public Object readItem() {
return answerRepository.findBy(23);
}
处理器:
public Object processItem(Object item) {
AnswerEntitiy answerEntitiy = (AnswerEntitiy)item;
//when i call answerEntitiy.getComment() LazyInitializationException throws
return commentRepository.findByAnswer(answerEntitiy); //works fine
}
作家:
public void writeItems(List<Object> items) {
//loops and casting
commentRepository.save(comment); //LazyInitializationException
}
这是完整的错误:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.AnswerEntitiy.comments, could not initialize proxy - no Session