1

我正在使用带有 Jaxb2Marshaller、PayloadRootAnnotationMethodEndpointMapping 和 GenericMarshallingMethodEndpointAdapter 的 spring-ws 通过 @Endpoint 和 @PayloadRoot 注释配置我的 Web 服务。

当我尝试使用我的项目的 DAO 时,我能够从数据库中加载对象,但是当我尝试访问服务中应该延迟加载的属性时,我得到一个 org.hibernate.LazyInitializationException - 无法初始化代理 -没有会话。

在我的 spring-mvc Web 应用程序中,OpenSessionInViewInterceptor 处理会话。如何配置我的 Web 服务项目以自动为每个 Web 服务调用创建 Hibernate 会话?

4

2 回答 2

2

将 org.springframework.aop.framework.ProxyFactoryBean 包裹在需要存在休眠会话的 spring 上下文中的对象周围。

这篇文章http://springtips.blogspot.com/2007/06/spring-and-hibernate.html展示了如何做到这一点。

如果您在以这种方式使用会话时由于延迟加载集合而遇到问题,则至少有 2 个可能的修复方法:

于 2009-01-21T22:41:19.947 回答
0

与此同时,我找到了解决方案。这个论坛条目给了我提示:

http://forum.springframework.org/showthread.php?t=50284

基本上,我将@Transactional 注释添加到我的Web 服务实现类中。棘手的部分是告诉 spring 使用我通过使用以下配置实现的原始类(不是由 tx:annotation-driven 创建的代理):

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" >
    <property name="order" value="1" />
</bean>

<tx:annotation-driven mode="proxy" order="200" proxy-target-class="true" />

配置语句的顺序似乎也很重要。

于 2009-01-27T09:21:56.663 回答