| Author |
LazyLoadException
|
Brian Mulholland
Ranch Hand
Joined: Mar 12, 2009
Posts: 54
|
|
|
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: 1282
|
|
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
|
|
Hello, what means OSIVF? O.o
|
 |
Bill Gorder
Bartender
Joined: Mar 07, 2010
Posts: 1282
|
|
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: 1282
|
|
Hebert,
Your link was good I just wanted to the OP to ignore that one option or at least be informed of it
|
 |
 |
|
|
subject: LazyLoadException
|
|
|