-->
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.  [ 4 posts ] 
Author Message
 Post subject: LazyInitializationException even with OpenSessionInViewFiltr
PostPosted: Tue Aug 01, 2006 11:34 am 
Newbie

Joined: Mon Jul 24, 2006 4:16 pm
Posts: 7
Location: Lapland
Hi,

I am using OpenSessionInViewFilter to enable lazy traversal of a collection, but it is still acting as it was before I used the filter. The message is:


org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.geai.b2b.domain.Environment.applications - no session or session was closed

My filter is configured like this:
<filter>
<filter-name>osivFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>osivFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>


I am using Hibernate 3, Spring 1.2, and Struts. The DAOs use HibernateTemplate and CMT through Spring - could this be causing a problem?

Any help is appreciated!

-Andrew

_________________
1-800-flowers.com? How on earth do you reach these people?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 12:53 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That exception also occurs when you modify a collection while it's still being loaded. Check your Environment.setApplications() method, and the set methods in the Application class (or whatever class is in the Environment.getApplications() collection). All set methods must be simple "memberVariable = passedParameter;" methods.

If you can't do without some code in your set methods, consider setting your mapping's default-access to "field".

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 1:45 pm 
Newbie

Joined: Mon Jul 24, 2006 4:16 pm
Posts: 7
Location: Lapland
All my getters and setters are "simple" ones, i.e. variable = value. I have no extra code in any of them.

Here is the DAO code where I get the Environment object:

public Environment findById(long environmentId)
{
List envs = getHibernateTemplate().find( "from Environment where id = ?", new Long(environmentId) );
if ( envs.size() > 0 )
return (Environment)envs.get(0);
else
return null;
}

As I mentioned, EnvironmentDao has CMT enabled through Spring, using HibernateTransactionManager. This includes the above method. Would ending the transaction before lazily traversing the collection (within the same request) cause this exception?

Thanks,

Andrew

_________________
1-800-flowers.com? How on earth do you reach these people?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 5:24 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It might if there's a lob in there: I've never used any lobs, but I've read that some DBMSs require lobs to be read from the result set before the transaction is ended. But if there's no lob involved, then it should work just fine.

I'm afraid that I can't see any obvious errors. I guess you'll have to start commenting bits out, or fire up the debugger. Sorry.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.