I found the problem. I was trying to be clever and
support a bi-directional relationship.
Message -- 1*
--> MessageMetaData
MessageMetaData -- *1 -->
Message
I had my SQLMap defined as follows for the MetaData
column:
result
column="Message_id" property="metaData" select="MessageMetaData.findByMessageId"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.
static class MessageMetaDataList extends
java.util.ArrayList<MessageMetaData> {
private Message message;
public MessageMetaDataList(Message message) {
super();
this.message = message;
}
private Message message;
public MessageMetaDataList(Message message) {
super();
this.message = message;
}
public void add(int index, MessageMetaData element)
{
element.setMessage(message);
super.add(index, element);
}
public boolean add(MessageMetaData o) {
o.setMessage(message);
return super.add(o);
}
element.setMessage(message);
super.add(index, element);
}
public boolean add(MessageMetaData o) {
o.setMessage(message);
return super.add(o);
}
public boolean addAll(Collection<? extends
MessageMetaData> c) {
for (Iterator iter = c.iterator(); iter.hasNext();) {
MessageMetaData mmd = (MessageMetaData) iter.next();
mmd.setMessage(message);
}
return super.addAll(c);
}
}
for (Iterator iter = c.iterator(); iter.hasNext();) {
MessageMetaData mmd = (MessageMetaData) iter.next();
mmd.setMessage(message);
}
return super.addAll(c);
}
}
And I would then
make certain that a passed in List of MetaData was properly
associated.
public void setMetaData(java.util.List<MessageMetaData> messageMetaData) {
this.metaData.addAll(messageMetaData);
}
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.
Any
suggestions?
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, May 24, 2007 10:25 PM
To: [EMAIL PROTECTED]; user-java@ibatis.apache.org
Subject: RE: Lazy Loading not working
Yes I do. The interesting thing is that Lazy loading is
working on some of my other objects but not on this one.
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of "Larry Meadors" <[EMAIL PROTECTED]>
Sent: Thursday, May 24, 2007 8:12 PM
To: user-java@ibatis.apache.org
Subject: Re: Lazy Loading not working
Larry
On 5/24/07, [EMAIL PROTECTED]
<[EMAIL PROTECTED]>wrote:
>
>
> I've got one SQLMap for an object that has children. For some reason when I
> execute a select and have properties of the result object perform selects to
> retrieve the adjacent objects the lazy load does not seem to work, but
> rather the adjacent select statements are being fired and the data is
> retrieved.
>
> I'm using iBatis 2.3.0.667
>
> My SQL Map Config has the following defined:
>
>
> errorTracingEnabled="true"
> enhancementEnabled="true"
> lazyLoadingEnabled="true"
> maxSessions="250"
> maxTransactions="30"
> maxRequests="500"
> useStatementNamespaces="true"/>
>
> My result Map looks as follows: (The ones in red seem to be fired every time
> no matter what)
>
>
>
>
>
>
>
>
>
>
>
>
>
> property="payload" select="Message.loadContent"/>
>
>
>
>
>
> Thanks for the help...
>
>
> Chris Mathrusse
> [EMAIL PROTECTED]
> (925) 236-5553
>