Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用容器管理的EntityManager进行会话管理_Java_Hibernate_Jpa_Apache Karaf_Karaf - Fatal编程技术网

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方法。

您可能对本文感兴趣: