Just to follow up, I tried Gilles Bayon's suggestion using the
cacheModel and did get everything working successfully.  Unfortunately
I did not realize that the cacheModel has no way to bypass the N+1
Selects issue.  If I understand things correctly, the cacheModel
actually stores the SQL query used to cache each object, so there is
no way to "prime" the cache using one large select statement and then
retrieve objects one-by-one using a parameter.  (I could be wrong
about this, but tried everything I could think of to test).

Using my original example, the intent was to cache all Stocks objects
from a table (using a single select statement) and then create
Position objects as needed, using the ticker of each Position to get a
reference to the cached Stock object.  This would ensure that, for
example, multiple positions in "IBM" point to the same Stock object.
In practice, however, I could not figure out a way to prime the cache
with all Stock objects aside from executing a separate SQL for each
one using the ticker as a parameter.

Hopefully that makes sense.  In any event, I think I am stuck writing
my own caching mechanism.  Thanks again for the help and please let me
know if I've overlooked something in the above analysis.

- Clyde

On Nov 11, 2007 8:56 AM, Clyde Coolidge <[EMAIL PROTECTED]> wrote:
> Thank you for the quick response.  This approach is exactly the
> direction I was heading after trying to use iBATIS' native
> functionality (in my case, using a static dictionary on the Stock
> class and a new constructor for the Position class which accepts a
> Stock as a parameter.)
>
> Separately, Gilles Bayon suggested using the cacheModel, which seems
> very promising as well.
>
> I am going to attempt both solutions on Monday and will report back
> once I get things working.  Thank you both for your help with this.
>
> > ---------- Forwarded message ----------
> > From: "Nicholas L. Piasecki" <[EMAIL PROTECTED]>
> > To: <[email protected]>
> > Date: Sat, 10 Nov 2007 17:12:15 -0500
> > Subject: RE: Question About Complex Types
> > As far as I know, there's no way to make iBATIS do this natively. You could
> > use your existing resultMaps and a QueryWithRowDelegate() and, in your row
> > delegate, add Stock objects to a Dictionary as you encounter them. Then,
> > manually assign the Stock object (pulling the object reference from your
> > Dictionary) and replace the duplicate one that iBATIS created.
> >
> > ...(snipped)...
>

Reply via email to