Java 使用容器管理的EntityManager进行会话管理
需要延迟获取集合。如果随后尝试访问其组件,则会出现以下异常:Java 使用容器管理的EntityManager进行会话管理,java,hibernate,jpa,apache-karaf,karaf,Java,Hibernate,Jpa,Apache Karaf,Karaf,需要延迟获取集合。如果随后尝试访问其组件,则会出现以下异常: failed to lazily initialize a collection of role: mapp3.model.ProductDefinition, could not initialize proxy - no Session Error executing command: Transaction management is not available for container managed EntityMan
failed to lazily initialize a collection of role:
mapp3.model.ProductDefinition, could not initialize proxy - no Session
Error executing command: Transaction management is not available for container managed EntityManagers.
因此,我通过以下方式从entityManager检索会话:
Session session = entityManager.unwrap(Session.class);
但这会导致以下例外情况:
failed to lazily initialize a collection of role:
mapp3.model.ProductDefinition, could not initialize proxy - no Session
Error executing command: Transaction management is not available for container managed EntityManagers.
我正在Karaf容器中使用Hibernate。否则,我将如何继续浏览延迟获取的集合,或者启动与容器管理的EntityManager的会话?看起来您正在EM上下文之外使用该实体。例如,如果它用于某些jsp等。
在从EM上下文发送集合之前,请调用集合的getter方法。您可能对本文感兴趣: