You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sven Haiges <ha...@yahoo.de> on 2008/07/17 20:38:09 UTC
Hibernate Session during CXF call
Hi all,
there must be a more elegant solution to an issue I have right now. I am using CXF to expose a SOAP-based interface to our data layer. This means in my spring config, I got bith Hibernate setup and also cxf. So calls would come in, hit the SOAP interface and the service implementations are then referencing a dataAccess object that does the hibernate calls.
This works fine, but I now experience the issue that I sometimes have to move around in my domain model and then some collecitons, references, are not yet initialized. And as I call those references from outside of the dataAccess (which opens and closes the hibernate session), I easily get exceptions.
My current solution would be to move the hibernateTemplate (from dataAccess) into my service implementation. During all operations, I would keep the session open till the very end. This would work, but it also kind of breaks the separation of concerns paradigm I guess.
What I actually need is something like the Spring OpenSessionInViewInterceptor just for CXF calls. A new Hibenrate session should be opened with each incoming call ot a service method and closed after completion.
Is this available fro CXF? If not, would it be diffcult to implement?
Cheers
Sven
---
Sven Haiges
Y! Messenger / Skype: hansamann
Re: Hibernate Session during CXF call
Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
Ian Roberts wrote:
> <bean id="hibernateInterceptor"
> class="org.springframework.orm.hibernate.HibernateInterceptor">
> <property name="sessionFactory" ref="..." />
> </bean>
Sorry, that probably wants to be orm.hibernate3 instead of orm.hibernate...
Ian
--
Ian Roberts | Department of Computer Science
i.roberts@dcs.shef.ac.uk | University of Sheffield, UK
Re: Hibernate Session during CXF call
Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
Sven Haiges wrote:
> What I actually need is something like the Spring
> OpenSessionInViewInterceptor just for CXF calls. A new Hibenrate
> session should be opened with each incoming call ot a service method
> and closed after completion.
>
> Is this available fro CXF? If not, would it be diffcult to implement?
Spring's HibernateInterceptor should do what you're after:
<bean id="hibernateInterceptor"
class="org.springframework.orm.hibernate.HibernateInterceptor">
<property name="sessionFactory" ref="..." />
</bean>
<bean id="realServiceImpl" class="my.service.Impl">
...
</bean>
<bean id="serviceImpl"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"><ref local="realServiceImpl"/></property>
<property name="interceptorNames">
<list>
<idref local="hibernateInterceptor" />
</list>
</property>
</bean>
<jaxws:endpoint implementor="#serviceImpl"
implementorClass="my.service.Impl" ... />
Ian
--
Ian Roberts | Department of Computer Science
i.roberts@dcs.shef.ac.uk | University of Sheffield, UK
Re: Hibernate Session during CXF call
Posted by Dan Retzlaff <dr...@gmail.com>.
Sven,
I take it the "moving around" occurs in custom interceptors? You can
definitely do your own Hibernate session management in interceptors. I did
it myself before I groked AOP and @Transactional. In fact, I think I
plagiarized the crux of it from OpenSessionInViewInterceptor. Just be sure
you catch the out fault case, or subsequent requests served by the same
thread will run into session-already-open problems. Also, since the
"sessionFactory.currentSession" context is the current thread (usually?), if
that handler chain thread swapping thing Dan Kulp mentioned recently
happens, you'll probably break.
Dan
On Thu, Jul 17, 2008 at 11:38 AM, Sven Haiges <ha...@yahoo.de> wrote:
> Hi all,
>
> there must be a more elegant solution to an issue I have right now. I am
> using CXF to expose a SOAP-based interface to our data layer. This means in
> my spring config, I got bith Hibernate setup and also cxf. So calls would
> come in, hit the SOAP interface and the service implementations are then
> referencing a dataAccess object that does the hibernate calls.
>
> This works fine, but I now experience the issue that I sometimes have to
> move around in my domain model and then some collecitons, references, are
> not yet initialized. And as I call those references from outside of the
> dataAccess (which opens and closes the hibernate session), I easily get
> exceptions.
>
> My current solution would be to move the hibernateTemplate (from
> dataAccess) into my service implementation. During all operations, I would
> keep the session open till the very end. This would work, but it also kind
> of breaks the separation of concerns paradigm I guess.
>
> What I actually need is something like the Spring
> OpenSessionInViewInterceptor just for CXF calls. A new Hibenrate session
> should be opened with each incoming call ot a service method and closed
> after completion.
>
> Is this available fro CXF? If not, would it be diffcult to implement?
>
> Cheers
> Sven
>
> ---
> Sven Haiges
> Y! Messenger / Skype: hansamann
>
>