Uploaded image for project: 'iBatis for Java [READ ONLY]'
  1. iBatis for Java [READ ONLY]
  2. IBATIS-717

add resultMap attribute to constructor/arg element

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.0 Beta 6
    • None
    • Core
    • None
    • all

    Description

      Hi All,

      I guess this is a corner case but it is pretty important one for projects with legacy data models.
      Let say there is a table in DB that contains:

      Column Type
      id int
      s1 string
      s2 string
      s3 string

      Also let say it is modeled (historically) by two immutable objects:

      public class ObjX

      { private final int id; private final String s1; private final ObjY objY; public ObjX( int id, String s1, ObjY objY ) { ... }

      }

      public class ObjY

      { private final String s2; private final String s3; public ObjY( String s2, String s3 ) { ... }

      }

      In this case there seems to be no way to build a result map for ObjX in iBatis without changing ObjX code but what if we cannot change it? And the requirement is to create objects via constructors only.

      It would be nice if we could use resultMap in <constructor>/<arg> element.
      This way one could write something like:

      <resultMap type="ObjX" id="ObjXResult">
      <constructor>
      <idArg column="id" javaType="_int" />
      <arg column="s1" javaType="String" />
      <arg javaType="ObjY" resultMap="ObjYResult"/>
      </constructor>
      </resultMap>

      <resultMap type="ObjY" id="ObjYResult">
      <constructor>
      <arg column="s2" javaType="String" />
      <arg column="s3" javaType="String" />
      </constructor>
      </resultMap>

      Comparable result could be achieved with TypeHandler but it will require column names to be hard-coded in the TypeHandler implementation also will require adding one TypeHandler per each such a case.

      Attachments

        Activity

          People

            Unassigned Unassigned
            osyabender Ostap Bender
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: