-->
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.  [ 7 posts ] 
Author Message
 Post subject: Toggling Lazy Setting per session
PostPosted: Wed Aug 30, 2006 3:43 am 
Newbie

Joined: Wed Aug 30, 2006 3:23 am
Posts: 4
Hi All,

I have an application using lazy="false" in hbm and the code written expects inner objects,hence I cannot make lazy="true" with out code changes.

Is there a way I can toggle lazy setting per session?
is there something like session.setLazy(boolean lazy). ?

or some other way to do it.

As I am using 3-T architecture I cannot keep session open till jps is rendered.

Cheers
-Praful


Top
 Profile  
 
 Post subject: lazy
PostPosted: Wed Aug 30, 2006 4:07 am 
Newbie

Joined: Tue Jul 11, 2006 4:22 pm
Posts: 9
Hi

try to use a session filter for hibernate session. than session is open for whole request
Or use Hibernate.initialize(.. collection or object) in servlet where you load objects ...

don't forget to rate ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:15 am 
Newbie

Joined: Wed Aug 30, 2006 3:23 am
Posts: 4
Hello blindmen1,

Thanks much for your reply,as I mention I am using 3-T architecture where my session is opened and closed at business layer and then object is transfered to web layer that gives call for lazy fetching.
hence I am looking for an approch where I will make lazy="True" when I donot need the inline objects (i.e there is no call to inline object at web layer) and will set it to false incase where inline objects are retrived at web layer

thanks again
-Praful


Top
 Profile  
 
 Post subject: lazy change true false
PostPosted: Wed Aug 30, 2006 4:26 am 
Newbie

Joined: Tue Jul 11, 2006 4:22 pm
Posts: 9
as far as i know there is not any setLazy() for collection.

I'm using lazy true everywhere.

In business layer (servlet) i load objects and use Hibernate.initialize(collection) to load a collection or object i know i will need in jsp. it will do the same as you want setLazy(false) on collection or object.

Or second aproach is to use a filter. On init request you will open hibernate session and you will close it after finish of the request.
http://jakarta.apache.org/turbine/turbi ... howto.html
i didn't read it but meybe it help ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:33 am 
Newbie

Joined: Wed Aug 30, 2006 3:23 am
Posts: 4
ya thats ture,using lazy true is best option,but i hvae to do changes to applaction that is already using lazy false,so find the ways that will make minimum impact on code.

neways thanks for you help,I will go thru the link try to find out solution.

Cheers
-Praful


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 9:43 am 
Beginner
Beginner

Joined: Wed Jun 21, 2006 10:08 am
Posts: 26
One strategy to use is Spring's IoC/AOP HibernateTransactionManager and it's OpenSessionInViewFilter or Interceptor.

If you let Spring handle your transactions there is no need to open sessions in the business logic. The transactions each handle the thread bound session. Within the view, if there are lazyily loaded objects, the Filter will obtain the current session and make use of it.

Essentially you remove boiler plate code and just worry about the business logic.

_________________
- Jonathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 2:26 am 
Newbie

Joined: Wed Aug 30, 2006 3:23 am
Posts: 4
Thanks much Jonathan,

it sounds great for spring applications,unfortunately my applicaion is not built using spring.
Thanks again.

Cheers
-Praful


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