ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry Meadors <larry.mead...@gmail.com>
Subject Re: Xml Result Mapping
Date Mon, 08 Aug 2005 22:15:23 GMT
I agree, iBATIS does 99% of what you want..but not the XML results.
Hmm, how do I say this nicely...the XML results that you get from
iBATIS suck. (No offense to Clinton, it seemed like a good idea to me,
too.)

There, I said it, and will have to live with it forever in the archives.

When you get a list as XML with iBATIS, you get something like this
(abbreviated):
<?xml version="1.0"
encoding="UTF-8"?><Account><accountid>1</accountid>...</Account>
<?xml version="1.0"
encoding="UTF-8"?><Account><accountid>2</accountid>...</Account>
<?xml version="1.0"
encoding="UTF-8"?><Account><accountid>3</accountid>...</Account>

So, each item in the list is a complete xml document, not a fragment
as you might expect. Obviously, sticking this inside another complete
xml document will make a big boom.

There are a couple of workarounds that I can think of: 

One is to get all the stuff as a complex collection, and then build
the xml from that. If you want easy coding, and do not care about
database performance, this is the way to go.

The other is to join all the data, and build a RowHandler to do it
(like you'd do if you were trying to fix the N+1 selects problem in
1.x). If you are concerned about database performance, and minimizing
the Java memory footprint, this is the way to go.

If you need more help, let us know...

Larry


On 8/8/05, Jason Vinson <vinson.lists@charter.net> wrote:
> Hi guys,
> 
> First off, sorry if you get this email twice, I sent the first from an
> un-subscribed email address.   Secondly, iBatis rocks!
> 
> I'm fairly new to iBatis, but I really dig it so far.  It's been a breeze to
> get result set -> pojo mapping for complex objects, but I'm having a bit of
> a tough time getting the same complex objects to map to xml.  I'm hoping you
> guys could provide some pointers, since I've not found much info on the
> internet regarding this.
> 
> Here's the rundown:
> 
> I have a pojo like so:
> 
> public class Entity {
> 
>     private String entityClass;
> 
>     private String entityClassId;
> 
>     private long id;
> 
>       private List attributes;
> 
>       private List relationshipsOut;
> 
>     private List relationshipsIn;
> 
>       /** all getters and setters **/
> }
> 
> And in my mapping file I have the following for the pojo mapping:
> 
> <resultMap class="Entity" id="entity-map" >
> 
>   <result property="id" column="id"/>
> 
>   <result property="entityClass" column="entityClass"/>
> 
>   <result property="entityClassId" column="classid"/>
> 
>   <result property="attributes" column="id"
>       select="getAttributesByEntityId"/>
> 
>   <result property="relationshipsOut" column="id"
>       select="getRelationshipsOutByEntityId"/>
> 
>   <result property="relationshipsIn" column="id"
>       select="getRelationshipsInByEntityId"/>
> 
> </resultMap>
> 
> 
> 
> <select id="getEntityById" resultMap="entity-map">
>     <![CDATA[
>       select i.entityid as id, e.name as entityClass, i.classid as classid
> 
>         from EntityClassification i, EntityClass e
>         where i.classid=e.id and i.entityid=#value#
>     ]]>
> 
> </select>
> 
> <!-- the other subselects are left out for brevity -->
> 
> I am aware that I can change the resultClass to "xml" for the Entity, but
> how can I get the sub-select elements (the three lists) to map to xml all at
> once?
> 
> Thanks for a great tool,
> Jason
> 
> 
>

Mime
View raw message