简体   繁体   English

使用容器管理的EntityManager进行会话管理

[英]Session management with a container managed EntityManager

A collection needs to be fetched lazily. 集合需要延迟获取。 If I then try to access its components, I get the following Exception : 如果然后尝试访问其组件,则会收到以下异常:

failed to lazily initialize a collection of role:
 mapp3.model.ProductDefinition, could not initialize proxy - no Session

So I retrieved the session from the entityManager this way: 因此,我以这种方式从entityManager检索了会话:

Session session = entityManager.unwrap(Session.class);

but this causes the following exception : 但这会导致以下异常:

Error executing command: Transaction management is not available for container managed EntityManagers.

I am using Hibernate inside a Karaf container. 我在Karaf容器中使用Hibernate。 How else could I proceed to either be able to browse the lazily fetched collection, either to start a Session with a container managed EntityMananger ? 我还能如何继续浏览延迟获取的集合,或者使用容器管理的EntityMananger启动会话?

Looks like you're using the entity outside of EM context. 看起来您正在使用EM上下文之外的实体。 eg. 例如。 if it used in some jsp etc. Please invoke getter method for the collection right before you're sending it out of EM context. 如果它在某些jsp等中使用过,请在从EM上下文发送出去之前立即调用该集合的getter方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM