ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject RE: Lazy Load is pre loading 1-1 relationships
Date Wed, 12 Sep 2007 17:17:47 GMT

<br><font size=2 face="sans-serif">Yes, I am aware of that little snafu.
I've been bitten by this one before. There is a WIKI on this one pertaining
to implementing a ResultObjectFactory that can potentially correct this
issue. I still need to look into it though.</font>
<br>
<br><font size=2 face="sans-serif">http://opensource.atlassian.com/confluence/oss/display/IBATIS/Lazy+loading+issues</font>
<br>
<br>
<br><font size=2 face="sans-serif">As it turns out the issue with Lazy
Loading was not caused by the serialVersionUID being declared. Upon further
research I found that someone had made a change to our base Domain object.
In the constructor, some of the classes set and get public methods were
being invoked. I'm guessing that the proxy class that is generated does
not discriminate method calls on the object even if initialization has
not been completed. For that reason, when the methods were invoked the
proxy was executing the sql and loading the object. I modified the constructor
to ensure that no public methods were invoked and this resolved the issue
for me.</font>
<br><font size=2 face="sans-serif"><br>
</font>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>&quot;MCCORMICK, Paul&quot;
&lt;Paul.McCORMICK@doir.wa.gov.au&gt;</b> </font>
<p><font size=1 face="sans-serif">09/11/2007 11:42 PM</font>
<table border>
<tr valign=top>
<td bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
user-java@ibatis.apache.org</font></div></table>
<br>
<td width=59%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td valign=top><font size=1 face="sans-serif">&lt;user-java@ibatis.apache.org&gt;</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">RE: Lazy Load is pre loading
1-1 relationships</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2 color=blue face="Comic Sans MS">Be careful with lazy loading
1-1 relationships where the lazy loaded result could be null. &nbsp;A proxy
object will be in its place.</font>
<br><font size=3>&nbsp;</font>
<br><font size=2 color=blue face="Comic Sans MS">e.g.</font>
<br><font size=2 color=blue face="Comic Sans MS">if ( foo.getBar() == null
) &nbsp;{ // Bar is lazy loaded.</font>
<br><font size=2 color=blue face="Comic Sans MS">&nbsp; &nbsp; // Unreachable
code</font>
<br><font size=2 color=blue face="Comic Sans MS">}</font>
<br>
<br>
<hr><font size=2 face="Tahoma"><b>From:</b> Poitras Christian [mailto:Christian.Poitras@ircm.qc.ca]
<b><br>
Sent:</b> Wednesday, 12 September 2007 4:05 AM<b><br>
To:</b> user-java@ibatis.apache.org<b><br>
Subject:</b> RE: Lazy Load is pre loading 1-1 relationships</font><font size=3><br>
</font>
<br><font size=2 color=blue face="Arial">It seems that is works with my
classes.</font>
<br><font size=3>&nbsp;</font>
<br><font size=2 color=blue face="Arial">I don't use</font>
<br><font size=2 color=#820040 face="Courier New"><b>private</b></font><font
size=2 face="Courier New">
</font><font size=2 color=#820040 face="Courier New"><b>static</b></font><font
size=2 face="Courier New">
</font><font size=2 color=#820040 face="Courier New"><b>final</b></font><font
size=2 face="Courier New">
</font><font size=2 color=#820040 face="Courier New"><b>long</b></font><font
size=2 face="Courier New">
</font><font size=2 color=#0021bf face="Courier New"><i>serialVersionUID</i></font><font
size=2 face="Courier New">
= -1699855014908794446L;</font><font size=3> </font>
<br><font size=2 face="Courier New">I use.</font><font size=2 color=#7f0055><b><br>
static</b></font><font size=2> </font><font size=2 color=#7f0055><b>final</b></font><font
size=2>
</font><font size=2 color=#7f0055><b>long</b></font><font
size=2> </font><font size=2 color=#0000c0><i>serialVersionUID</i></font><font
size=2>
= 7213712437136303104L;</font>
<br><font size=3>&nbsp;</font>
<br><font size=2 color=blue face="Arial">Give it a try!</font>
<br><font size=2 color=blue face="Arial">Christian</font>
<br><font size=3>&nbsp;</font>
<br>
<br>
<hr><font size=2 face="Tahoma"><b>From:</b> Christopher.Mathrusse@sybase.com
[mailto:Christopher.Mathrusse@sybase.com] <b><br>
Sent:</b> Tuesday, 11 September 2007 15:57<b><br>
To:</b> user-java@ibatis.apache.org<b><br>
Subject:</b> RE: Lazy Load is pre loading 1-1 relationships</font><font size=3><br>
</font>
<br><font size=2 face="sans-serif"><br>
That was it! I removed the variable definition from all my domain objects,
performed a clean and build and the lazy loading is now working correctly.
Thanks for the suggestion.</font><font size=3> <br>
<br>
<br>
<br>
</font>
<table width=100%>
<tr valign=top>
<td width=44%><font size=1 face="sans-serif"><b>Christopher.Mathrusse@sybase.com</b>
</font>
<p><font size=1 face="sans-serif">09/11/2007 12:30 PM</font><font size=3>
</font>
<br>
<table border=4 width=100%>
<tr valign=top>
<td width=100% bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
user-java@ibatis.apache.org</font></div></table>
<p>
<td width=55%>
<br>
<table width=100%>
<tr>
<td width=15%>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td width=84% valign=top><font size=1 face="sans-serif">user-java@ibatis.apache.org</font><font
size=3>
</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top><font size=1 face="sans-serif">user-java@ibatis.apache.org</font><font
size=3>
</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">RE: Lazy Load is pre loading
1-1 relationships</font></table>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=49%>
<td width=50%></table>
<br></table>
<br><font size=3><br>
<br>
</font><font size=2 face="sans-serif"><br>
<br>
This may actually answer my question. I recently added to my domain objects
the following:</font><font size=3> </font><font size=2 color=#820040
face="Courier New"><b><br>
<br>
private</b></font><font size=2 face="Courier New"> </font><font
size=2 color=#820040 face="Courier New"><b>static</b></font><font
size=2 face="Courier New">
</font><font size=2 color=#820040 face="Courier New"><b>final</b></font><font
size=2 face="Courier New">
</font><font size=2 color=#820040 face="Courier New"><b>long</b></font><font
size=2 face="Courier New">
</font><font size=2 color=#0021bf face="Courier New"><i>serialVersionUID</i></font><font
size=2 face="Courier New">
= -1699855014908794446L;</font><font size=3> </font><font size=2 face="sans-serif"><br>
<br>
I added this to eliminate the warning that Eclipse was giving me. Any object
that I needed to touch as of recently I would add this to. The domain objects
that are not lazily loading seem to be the ones that I added serialVersionUID
to.</font><font size=3> </font><font size=2 face="sans-serif"><br>
<br>
Thanks for the help...</font><font size=3> <br>
<br>
<br>
</font>
<table width=100%>
<tr valign=top>
<td width=53%><font size=1 face="sans-serif"><b>&quot;Poitras Christian&quot;
&lt;Christian.Poitras@ircm.qc.ca&gt;</b> </font>
<p><font size=1 face="sans-serif">09/11/2007 12:22 PM</font><font size=3>
</font>
<br>
<table border=4 width=100%>
<tr valign=top>
<td width=100% bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
user-java@ibatis.apache.org</font></div></table>
<br>
<td width=46%>
<br>
<table width=100%>
<tr>
<td width=15%>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td width=84% valign=top><font size=1 face="sans-serif">&lt;user-java@ibatis.apache.org&gt;</font><font
size=3>
</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">RE: Lazy Load is pre loading
1-1 relationships</font></table>
<br><font size=3><br>
</font>
<br>
<table width=100%>
<tr valign=top>
<td width=49%>
<td width=50%></table>
<br></table>
<br><font size=3><br>
<br>
</font><font size=2 color=blue face="Arial"><br>
<br>
I doubt my reply will answer your question, but this is mostly for information
purpose.</font><font size=3> <br>
 </font><font size=2 color=blue face="Arial"><br>
All final classes are never lazy loaded by iBATIS. This include any primitive
type, Strings and this like Integer, Double, etc...</font><font size=3>
</font><font size=2 color=blue face="Arial"><br>
This &quot;bug&quot; is probably due to the fact that cglib tries to extend
the class. If it is final, it must be loaded now.</font><font size=3> <br>
 </font><font size=2 color=blue face="Arial"><br>
Christian</font><font size=3> <br>
<br>
</font>
<hr><font size=2 face="Tahoma"><b>From:</b> Christopher.Mathrusse@sybase.com
[mailto:Christopher.Mathrusse@sybase.com] <b><br>
Sent:</b> Tuesday, 11 September 2007 15:12<b><br>
To:</b> user-java@ibatis.apache.org<b><br>
Subject:</b> Lazy Load is pre loading 1-1 relationships</font><font size=2
face="sans-serif"><br>
<br>
<br>
I've been spending a fair amount of time on this now but I can't seem to
get any further. Objects that I am attempting to load lazily are simply
loading. The relationships that are 1-M seem to be fine, meaning that they
are not pre-loading, but any relationship that I have that is a 1-1 seems
to be loaded when the resultSet is applied to the parent object. Is there
anything I can do to prevent this from happening?</font><font size=3> </font><font
size=2 face="sans-serif"><br>
<br>
Thanks...</font><font size=3> </font>
<table width=100%>
<tr>
<td width=100% bgcolor=white><font size=3>&quot;DISCLAIMER: This email,
including any attachments, is intended only for use by the addressee(s)
and may contain confidential and/or personal information and may also be
the subject of legal privilege. If you are not the intended recipient,
you must not disclose or use the information contained in it. In this case,
please let me know by return email, delete the message permanently from
your system and destroy any copies. <br>
<br>
Before you take any action based upon advice and/or information contained
in this email you should carefully consider the advice and information
and consider obtaining relevant independent advice.</font></table>
<br>
<br>

Mime
View raw message