春季Web服务中的Hibernate会话处理 [英] Hibernate session handling in spring web services

查看:164
本文介绍了春季Web服务中的Hibernate会话处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用spring-ws与Jaxb2Marshaller,PayloadRootAnnotationMethodEndpointMapping和GenericMarshallingMethodEndpointAdapter通过@Endpoint和@PayloadRoot注释配置我的Web服务。



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



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

解决方案

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



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



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

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

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

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

I am using spring-ws with Jaxb2Marshaller, PayloadRootAnnotationMethodEndpointMapping and GenericMarshallingMethodEndpointAdapter to configure my web services via the @Endpoint and @PayloadRoot annotations.

When I try to use the DAO's of my project I am able to load objects from the database but as soon as I try to access properties inside my service that should be lazily loaded I get a org.hibernate.LazyInitializationException - could not initialize proxy - no Session.

In my spring-mvc web application the OpenSessionInViewInterceptor handles the sessions. How do I configure my web service project to automatically create a Hibernate session for every web service call?

解决方案

In the meanwhile I found a solution. This forum entry gave me the hint:

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

Basically I added the @Transactional annotations to my web service implementation class. The tricky part was to tell spring to use the original class (not the proxy created by tx:annotation-driven) which I achieved by using the following configuration:

<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" />

The order of the configuration statements seems important too.

这篇关于春季Web服务中的Hibernate会话处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆