-->
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.  [ 3 posts ] 
Author Message
 Post subject: About lazy = "true" and session .close() question.
PostPosted: Wed Jul 02, 2008 11:52 am 
Newbie

Joined: Wed Jul 02, 2008 11:17 am
Posts: 1
Recently I was developing a system. I met a problem like that.

When web page send a request for some data to display , then back end receive this request . I use Hibernate select some results meeting with request from database , then send these results to web page. When I finished
the select operation, I closed the session. (I use the "lazy=""true" about collection). But when web page display the results, some lazy initial data haven't initialized,however, the session had been closed. Since the session had been closed, lazy initial data couldn't initialize themselves on the web page. So I want to know whether some methods could solve this queston?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 03, 2008 5:59 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
FAQ Open Session in View

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 1:34 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
The key is to keep your Sessions open longer. Many queries within one transaction, all branching an open session, is a very common and accepted design strategy, if not a design pattern.

As was mentioned, the Open Session in View pattern embraces this idea. It's easily implemented as a ServletFilter in a web based application.

Here's a little tutorial on How Hibernate Works. It explains a little about how the Hibernate3 Session works and how to avoid HibernateException types such as the ObjectNotFoundException and more to the point, LazyInitializationException:

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=07howhibernateworks

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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