ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Lamey <cla...@localmatters.com>
Subject Re: Populating existing beans...
Date Tue, 12 Sep 2006 20:53:12 GMT
I think he's saying he wants iBATIS to populate already existing beans
in a map rather than create new beans.  So basically "Bean b =
byId.get(beanId)" rather than "new Bean()".  I guess the iBATIS call
would be something like populateMap(statementName, parameterObject, key,
mapWithExistingObjects).

If that's true, I'm pretty sure this doesn't exist now and I doubt it
would be high on the priority list.

Your best bet would be to use the existing methods and then process the
object after they've been populated by iBATIS.  In general, the model
objects iBATIS returns are intended to represent rows in a table, so
merging them with existing objects whose member variables don't mimic
the table structure doesn't really fit in the iBATIS scheme all that
well.  Using some kind of composite object layer on top of the iBATIS
models that pulls things together might be a better route.

Cheers,
Chris

On Tue, 2006-09-12 at 14:24 -0600, Diran Ayandele wrote:
> Daniel, there is queryForMap functionality in iBatis.  It looks like
> this: SqlMapExecutor.queryForMap(statementName, parameterObject, key).
> The key will be a column in your result map which could be your
> bean.id property after the result map populates the bean.  I am not
> sure what you mean by populating existing beans, but I hope this
> helps.
> 
> Diran
> 
> Daniel Pitts wrote: 
> > I have a 
> > Map<Integer, MyBean> byId;
> > Which was built by "byId.put(myBean.getId(), myBean);"
> > MyBean is the base class, there are many types of "MyBean" objects.
> > 
> > Is there a away to tell iBATIS to use the bean in "byId" map as the
> > result object? Or do I have to get the result, and copy the values over
> > myself?
> > 
> > I know it can be done with queryForObject(String, Object, Object); but I
> > need it for something like queryForList or queryForMap
> > 
> > Thanks,
> > Daniel.
> >   

Mime
View raw message