-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Lazy loading Issue
PostPosted: Sun Feb 14, 2010 9:18 pm 
Newbie

Joined: Tue Jun 17, 2008 11:01 pm
Posts: 16
I just introduced hibernate to my new project using spring + hibernate + dwr,

All the hibernate configuration are done in the dispatcher-servlet.xml (transaction etc..),

my project lay out look like this

DwrLayer --> FacadeLayer --> Servicelayer --> DaoLayer

In the above four java class , transaction applied in FacadeLayer, so if i select some data from table with lazy loading is true, i can access all fields from FacadeLayer or Servicelayer or DaoLayer with out any lazy loading errors,
But if i returned data from DwrLayer, then the lazy -true object will thrown errors, So i force to do, that setting all unwanted lazy-true object as null with in FacadeLayer before return.

Is there is any way to do it safely withg out setting object as null ?

Thanks in advance


Top
 Profile  
 
 Post subject: Re: Lazy loading Issue
PostPosted: Sun Feb 14, 2010 11:06 pm 
Newbie

Joined: Tue Jun 02, 2009 4:06 am
Posts: 16
Hi,

This is because tyou are trying to access the collection object outside the scope of the session you created.The collection object hasn't been initialised as you require it only when you access it from you rdwr layer.You close the session in your facade layer and then access it from dwr layer which is out of your Hibernate session scope.This problem can be resolved by using "OpenSessionInView"Interceptor.

There are two ways to resolve your issue keeping lazy="true" as it is.

1)In your dispatcher-servlet.xml add the following entry

<bean id="openSessionInViewInterceptor"
class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">

and the refer this interceptor in your handler mapping.Let say you are using SimpleHandlerMapping then you can inject it as shown below.

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="openSessionInViewInterceptor"/>
</list>
</property>
<property name="mappings">
<props>
<prop key="/login.do">logginController</prop>
</props>


OR

2) Add the following in your web.xml where servlet-name should be the same name you gave it for your Dispatcher servlet.

<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>


kartik


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.