This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes LazyLoadException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "LazyLoadException" Watch "LazyLoadException" New topic
Author

LazyLoadException

Brian Mulholland
Ranch Hand

Joined: Mar 12, 2009
Posts: 61
I am modifying a Hibernate/Spring/Wicket webapp that was misusing sessions and not lazy loading. Along the way, wicket calls back into what I believe is a detached model to lazy load and produces a LazyLoadexception. What is the appropriate solution to this? I presume that I want to force Hibernate to prefetch that bean's data while the session is alive. How do I do that? Or rather, what is the "right" way to do that? I suppoose I could go into the object and invoke the methods one by one that will be needed. Is there a better way or is that the way this is done?
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Check this post: http://uaihebert.com/?p=1383


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

If the data is always needed I would change the association to be eagerly fetched. If you only need the data eagerly fetched in certain scenarios I would do that in the query. For the hibernate way see
http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#queryhql-joins

If you are using jpa see fetch joins
http://docs.oracle.com/html/E24396_01/ejb3_langref.html#ejb3_langref_fetch_joins

I would not use OSIVF!

[How To Ask Questions][Read before you PM me]
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Bill Gorder wrote:If the data is always needed I would change the association to be eagerly fetched. If you only need the data eagerly fetched in certain scenarios I would do that in the query. For the hibernate way see
http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#queryhql-joins

If you are using jpa see fetch joins
http://docs.oracle.com/html/E24396_01/ejb3_langref.html#ejb3_langref_fetch_joins

I would not use OSIVF!
Hello, what means OSIVF? O.o
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Hebert,

Open Session In View Filter I guess I actually should have said 'Open Session In View' the filter is one of the implementations I commonly see.

I feel this is an anti pattern and steer clear of it. Summarized pretty well in tip 4 of this blog:
http://www.realsolve.co.uk/site/tech/orm-performance.php
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Bill Gorder wrote:Hebert,

Open Session In View Filter I guess I actually should have said 'Open Session In View' the filter is one of the implementations I commonly see.

I feel this is an anti pattern and steer clear of it. Summarized pretty well in tip 4 of this blog:
http://www.realsolve.co.uk/site/tech/orm-performance.php
Ok! I know Open Session In View, but I could not figure it out from OSIVF. ^^
The link that I posted above display 4 ways to solve Lazy Exception, but there is more. [=
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Hebert,

Your link was good I just wanted to the OP to ignore that one option or at least be informed of it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LazyLoadException
 
Similar Threads
annotation for lazy loading
Which framework is Wicket closely related to?
Wicket, the big door for Java developers
Transaction handling in 3-tier layered application using Wicket + Spring + Hibernate
lazy loading