Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LazyLoadException

 
Brian Mulholland
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hebert,

Your link was good I just wanted to the OP to ignore that one option or at least be informed of it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic