ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Vinson <vinson.li...@charter.net>
Subject Xml Result Mapping
Date Mon, 08 Aug 2005 15:04:28 GMT
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