-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate and Lazy Instantiation - from the UI
PostPosted: Tue Jul 13, 2004 11:57 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
I have been reading various posts on this topic. The most significant being: http://www.hibernate.org/124.html

I was wondering is there some pattern or design to allow lazy instantiation failover? Such as from the UI.

The very simplest would be have a configuration such that you could catch LazyInstantiationException and then take the suspect object and lock it to a newly created session.

One example I have of this is using the DisplayTag TagLib. If I don't preload the entire bean list that I pass to the UI it will throw an exception if I try to do an XML export etc. To work around this I have only found 2 solutions. The first is to preload every attribute of each bean at the DAO level when I retrieve them. This is obvously not a great solution. The second is to call a specific method in my DAO to preload specific attributes of the beans. This also is not the best since I have to anticipate what attributes will be accessed.

Another solution that I am considering is to somehow intercept the 'LazyInstantiationException' and have the framework auto associate the object with a new or current session. I am not sure how to approach this exactly and would welcome comments.

Thanks

Troy McKinnon


Top
 Profile  
 
 Post subject: No takers
PostPosted: Wed Jul 14, 2004 3:07 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
No takers on this?

I would really appreciate some direction on this one.

Troy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 14, 2004 3:08 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This has been discussed many times, search the forum.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: search the forum
PostPosted: Wed Jul 14, 2004 4:28 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
I had search the forum, and unless I missed something I didn't see any definitive answers to my question.

From what I read you basically HAVE to preload everything you plan on using.. so you need knowledge of what the user will do before they do it.

I didn't see anything particular to optimizing this preloading by allow some type of callback or after the fact rebinding of an element if Exception was thrown.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 6:15 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
I prefer the eager fetching, described in chapter 7 of HIA.
In short: when your are constructing HQL query or Criteria, you can specify eager fetching for some lazy associations that you are going to use with:
left join fetch in HQL query or Criteria.setFetchMode with FetchMode.EAGER.

--
Leonid


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