-->
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: LazyInitializationException - Design Issue
PostPosted: Fri Apr 15, 2005 11:17 am 
Newbie

Joined: Fri Mar 18, 2005 6:09 am
Posts: 3
Hi,

I am fairly new to Hibernate and am trying to develop a Swing application using Hibernate 3 to persist my domain objects. I am trying to design my application using "best practices" i.e. making sure there is a clean separation of layers etc.

My question relates to Lazy Initialisation of collections. I keep hitting a LazyInitializationException - I understand why - I am closing the session before accessing a collection that is lazily loaded. The question I have is where should I open and close the session. Also, I have a problem with having to open the session just because I have a collection that is lazily loaded. Surely there must be some way of automagically opening the correct session when I access the lazily loaded collection.

Sorry for not posting anything specific - I suppose this is a general design question. Thanks for all your hard work.

Malcolm


Top
 Profile  
 
 Post subject: Re: LazyInitializationException - Design Issue
PostPosted: Fri Apr 15, 2005 11:40 am 
Beginner
Beginner

Joined: Thu Mar 24, 2005 5:21 pm
Posts: 21
Mmm - sounds like you want to use Application Transactions where you keep the Hibernate session open till a logical user transaction completes. This will probably influence the way you design your Swing app as well - in terms of walking the user through a defined set of use-cases rather than allow him to skip around in a more random way.
You can find more information about application transactions both on the website and in the book (HIA, Manning Press).
HTH
Satish

PS Alternatively, you could initialise proxies (both single-valued entities and collections) explicitly as needed using Hibernate.initialize(...) and/or use detached objects...


Top
 Profile  
 
 Post subject: Lazily instantiated Desing Issue Swing
PostPosted: Tue Apr 19, 2005 10:43 am 
Newbie

Joined: Fri Mar 18, 2005 6:09 am
Posts: 3
Thanks for your input. I have done lots of Googling on this issue and it sounds as if the various Session strategies for web based applications are well thought out - alas, not for Swing apps.

I think that I am going to have to write a business facade and instead of calling foo.getBars() I will have to know that bars are lazily instantiated and so call BusinessFacade.getBars(foo). BusinessFacade.getBars(foo) will attach back to the session and initialise the collection.

Not the most ideal solution - but what is :-)

Cheers

Malcolm


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.