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 Loading not working
Date Fri, 25 May 2007 17:59:24 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii" html; text 
Content-Type:>
<META content="MSHTML 6.00.6000.16441" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=815414317-25052007>I found the problem. I was trying to be clever and 
support a bi-directional relationship.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=815414317-25052007></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=815414317-25052007>Message -- 1* 
--&gt;&nbsp;MessageMetaData</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=815414317-25052007>MessageMetaData -- *1 --&gt; 
Message</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT><SPAN class=815414317-25052007></SPAN></FONT><FONT

face=Arial><FONT color=#0000ff><FONT size=2></FONT></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff 
size=2></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=815414317-25052007><FONT face=Arial 
color=#0000ff size=2>I had my SQLMap defined as follows for the MetaData 
column:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=815414317-25052007><FONT color=#3f7f7f

size=2>
<P>result </FONT><FONT color=#7f007f size=2>column</FONT><FONT

size=2>=</FONT><FONT color=#2a00ff size=2>"Message_id" </FONT><FONT

color=#7f007f size=2>property</FONT><FONT size=2>=</FONT><FONT color=#2a00ff

size=2>"metaData" </FONT><FONT color=#7f007f size=2>select</FONT><FONT

size=2>=</FONT><FONT color=#2a00ff 
size=2>"MessageMetaData.findByMessageId"</FONT></P>
<P><FONT face=Arial color=#0000ff size=2><SPAN class=815414317-25052007>I

already know that iBatis cannot support a circular relationship so the 
MessageMetaData SQLMap did not try to load the Message associated to the 
MetaData. Instead I tried a little trick inside the Message class where I 
created an inner class that extended ArrayList, that would associate the Message 
to each MetaData element. </SPAN></FONT><FONT color=#2a00ff 
size=2></P></FONT></SPAN></DIV>
<DIV><FONT style="BACKGROUND-COLOR: #ffffff" face=Arial color=#0000ff 
size=2>&nbsp;static class MessageMetaDataList extends 
java.util.ArrayList&lt;MessageMetaData&gt; {<BR>&nbsp;&nbsp;private
Message 
message;<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;public MessageMetaDataList(Message

message) {<BR>&nbsp;&nbsp;&nbsp;super();<BR>&nbsp;&nbsp;&nbsp;this.message
= 
message;<BR>&nbsp;&nbsp;}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT style="BACKGROUND-COLOR: #ffffff" face=Arial color=#0000ff 
size=2>&nbsp;&nbsp;public void add(int index, MessageMetaData element) 
{<BR>&nbsp;&nbsp;&nbsp;element.setMessage(message);<BR>&nbsp;&nbsp;&nbsp;super.add(index,

element);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;public
boolean 
add(MessageMetaData o) 
{<BR>&nbsp;&nbsp;&nbsp;o.setMessage(message);<BR>&nbsp;&nbsp;&nbsp;return

super.add(o);<BR>&nbsp;&nbsp;}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT style="BACKGROUND-COLOR: #ffffff" face=Arial color=#0000ff 
size=2>&nbsp;&nbsp;public boolean addAll(Collection&lt;? extends 
MessageMetaData&gt; c) {<BR>&nbsp;&nbsp;&nbsp;for (Iterator iter = c.iterator();

iter.hasNext();) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageMetaData mmd =

(MessageMetaData) 
iter.next();<BR>&nbsp;&nbsp;&nbsp;&nbsp;mmd.setMessage(message);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;return

super.addAll(c);<BR>&nbsp;&nbsp;}<BR>&nbsp;}</FONT></DIV>
<DIV><FONT style="BACKGROUND-COLOR: #ffffff" face=Arial color=#0000ff 
size=2></FONT>&nbsp;</DIV>
<DIV><FONT style="BACKGROUND-COLOR: #ffffff"><SPAN 
class=815414317-25052007><FONT face=Arial color=#0000ff size=2>And I would then 
make certain that a passed in List of MetaData was properly 
associated.</FONT></SPAN></FONT></DIV>
<DIV><FONT style="BACKGROUND-COLOR: #ffffff"><SPAN 
class=815414317-25052007><FONT face=Arial color=#0000ff size=2><BR>&nbsp;public

void setMetaData(java.util.List&lt;MessageMetaData&gt; messageMetaData) 
{<BR>&nbsp;&nbsp;this.metaData.addAll(messageMetaData);<BR>&nbsp;}</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=815414317-25052007>This

is where the problem lies. By accessing the passed in List the SQL Statement was 
executed and loaded all associated objects. Clearly this will not work so I 
can't think of a clean way to support a bi-directional relationship. 
</SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=815414317-25052007></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=815414317-25052007>Any

suggestions?</SPAN></FONT></DIV>
<DIV><BR></FONT><BR></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Christopher.Mathrusse@sybase.com 
[mailto:Christopher.Mathrusse@sybase.com] <BR><B>Sent:</B> Thursday, May
24, 
2007 10:25 PM<BR><B>To:</B> lmeadors@apache.org; 
user-java@ibatis.apache.org<BR><B>Subject:</B> RE: Lazy Loading not 
working<BR></FONT><BR></DIV>
<DIV></DIV>
<META content="MSHTML 6.00.6000.16441" name=GENERATOR>
<DIV dir=ltr align=left><SPAN class=187502405-25052007><FONT face=Arial 
color=#0000ff size=2>Yes I do. The interesting thing is that Lazy loading is 
working on some of my other objects but not on this one.</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> larry.meadors@gmail.com 
[mailto:larry.meadors@gmail.com] <B>On Behalf Of </B>"Larry Meadors" 
&lt;lmeadors@apache.org&gt;<BR><B>Sent:</B> Thursday, May 24, 2007
8:12 
PM<BR><B>To:</B> user-java@ibatis.apache.org<BR><B>Subject:</B>
Re: Lazy Loading 
not working<BR></FONT><BR></DIV>
<DIV></DIV>Do you have cglib on your classpath? <BR><BR>Larry <BR><BR><BR>On

5/24/07, Christopher.Mathrusse@sybase.com 
<BR><CHRISTOPHER.MATHRUSSE@SYBASE.COM>wrote: <BR>&gt; <BR>&gt;
<BR>&gt; I've got 
one SQLMap for an object that has children. For some reason when I <BR>&gt; 
execute a select and have properties of the result object perform selects to 
<BR>&gt; retrieve the adjacent objects the lazy load does not seem to work, but

<BR>&gt; rather the adjacent select statements are being fired and the data is 
<BR>&gt; retrieved. <BR>&gt; <BR>&gt; I'm using iBatis 2.3.0.667
<BR>&gt; 
<BR>&gt; My SQL Map Config has the following defined: <BR>&gt; <BR>&gt;

<SETTINGS <BR>&gt; cacheModelsEnabled="true" <BR>&gt; errorTracingEnabled="true"

<BR>&gt; enhancementEnabled="true" <BR>&gt; lazyLoadingEnabled="true"
<BR>&gt; 
maxSessions="250" <BR>&gt; maxTransactions="30" <BR>&gt; maxRequests="500"

<BR>&gt; useStatementNamespaces="true"/&gt; <BR>&gt; <BR>&gt;
My result Map 
looks as follows: (The ones in red seem to be fired every time <BR>&gt; no 
matter what) <BR>&gt; <BR>&gt; <RESULTMAP class=Message 
id=MessageResult><BR>&gt; <RESULT column="Message_id" jdbcType="NUMERIC" 
property="id" /><BR>&gt; <RESULT column="Message_type" jdbcType="VARCHAR"

property="type" /><BR>&gt; <RESULT column="Message_state" jdbcType="VARCHAR"

property="state" /><BR>&gt; <RESULT <BR column="Message_previous_state"

jdbcType="VARCHAR">&gt; property="previousState" /&gt; <BR>&gt; <RESULT
<BR 
column="Message_document_identifier">&gt; jdbcType="VARCHAR" 
property="documentIdentifier"/&gt; <BR>&gt; <RESULT <BR 
column="Message_purchase_order_no">&gt; jdbcType="VARCHAR" 
property="poNumber"/&gt; <BR>&gt; <RESULT <BR column="Message_order_no"

jdbcType="VARCHAR" property="order">&gt; 
select="RequestOrder.findByPrimaryKey"/&gt; <BR>&gt; <RESULT <BR 
column="Message_create_date" jdbcType="TIMESTAMP">&gt; property="createDate" 
/&gt; <BR>&gt; <RESULT <BR column="Message_mod_date" jdbcType="TIMESTAMP">&gt;

property="modifiedDate" /&gt; <BR>&gt; <RESULT <BR column="Message_version"

jdbcType="INTEGER" property="version">&gt; /&gt; <BR>&gt; <RESULT
<BR>&gt; 
column="{textPointer=Payload_text_pointer,dataLength=Payload_data_length}" 
<BR>&gt; property="payload" select="Message.loadContent"/&gt; <BR>&gt;
<RESULT 
<BR column="Message_parent_id" property="parent">&gt; 
select="Message.findByPrimaryKey"/&gt; <BR>&gt; <RESULT <BR column="Message_id"

property="metaData">&gt; select="MessageMetaData.findByMessageId"/&gt; <BR>&gt;

</RESULTMAP><BR>&gt; <BR>&gt; <BR>&gt; Thanks for the
help... <BR>&gt; <BR>&gt; 
<BR>&gt; Chris Mathrusse <BR>&gt; christopher.mathrusse@sybase.com <BR>&gt;

(925) 236-5553 <BR>&gt; <BR><BR></BODY></HTML>


Mime
View raw message