emacarron / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

Multiple column selected resultMap #149

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the MyBatis are you using? 3.0.2

Please describe the problem.  Unit tests are best!

I'm building an object graph in a result map using the "nested selects" method 
in the documentation.  That is, I have multiple select statements cascading 
from one resultMap.

Everything works great if I have only one column on the select statements.  The 
object graph is created by the resultMap as expected and it passes all unit 
tests. w00t!

The problem comes if I would like to add a second column to one of the 
collections.  I've tried every conceivable variation on the "{prop1=col1, 
prop2=col2}" syntax, but it doesn't work.

This works just fine:

   <resultMap id="invoiceObjectGraph" 
       type="com.rolandus.rolex.beans.SroishObjGraph" >
     <association property="invoiceHeader" column="IHINVN"
       javaType="com.rolandus.rolex.beans.SroishBean"
       select="selectOneInvoice"/>
     <association property="paymentTerm" column="IHTOPC"
       javaType="com.rolandus.rolex.beans.SroctlsjBean"
       select="selectOnePaymentTerm"/>
     <collection property="invoiceLines" column="IHINVN" 
       javaType="List" ofType="com.rolandus.rolex.beans.SroisdplBean" 
       select="selectInvoiceLines"/>
     <collection property="invoiceCharges" column="ihinvn"
       javaType="List" ofType="com.rolandus.rolex.beans.SroisaBean"
       select="selectInvoiceCharges"/> 
   </resultMap>
   <select id="selectInvoiceObjGraph"  
           parameterType="int" resultMap="invoiceObjectGraph" >
     select IHINVN, IHTOPC, IHTYPP, IHINYY, IHORNO
     from SROISH 
     where ihinvn = #{ihinvn}
   </select>
   <select id="selectInvoiceCharges"
           resultType="com.rolandus.rolex.beans.SroisaBean" >
    select IAINVN, IATYPP, IAINYY, IACODE, IAAMOU
      from SROISA
     where iainvn = #{ihinvn} 
    </select> 

This does not work:

  <!-- Focus on the IHINVN, IHTYPP from file SROISH and IAINVN, IATYPP from file SROISA -->

  <resultMap id="invoiceObjectGraph" 
       type="com.rolandus.rolex.beans.SroishObjGraph" >
     <association property="invoiceHeader" column="IHINVN"
       javaType="com.rolandus.rolex.beans.SroishBean"
       select="selectOneInvoice"/>
     <association property="paymentTerm" column="IHTOPC"
       javaType="com.rolandus.rolex.beans.SroctlsjBean"
       select="selectOnePaymentTerm"/>
     <collection property="invoiceLines" column="IHINVN" 
       javaType="List" ofType="com.rolandus.rolex.beans.SroisdplBean" 
       select="selectInvoiceLines"/>
     <collection property="invoiceCharges" column="{ihinvn, ihtypp}"
       javaType="List" ofType="com.rolandus.rolex.beans.SroisaBean"
       select="selectInvoiceCharges"/> 
   </resultMap>
   <select id="selectInvoiceObjGraph"  
           parameterType="int" resultMap="invoiceObjectGraph" >
     select IHINVN, IHTOPC, IHTYPP, IHINYY, IHORNO
     from SROISH 
     where ihinvn = #{ihinvn}
   </select>
   <select id="selectInvoiceCharges"
           resultType="com.rolandus.rolex.beans.SroisaBean" >
    select IAINVN, IATYPP, IAINYY, IACODE, IAAMOU
      from SROISA
     where iainvn = #{ihinvn} and iatypp = #{ihtypp}
    </select> 

What is the expected output? What do you see instead?

The above configuration gets the following: 

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: 
org.apache.ibatis.reflection.ReflectionException: There is no setter for 
property named 'ihinvn' in 'class java.lang.Object'

Changing it as follows gets the same result:

    <collection property="invoiceCharges" 
       column="{ihinvn=iainvn, ihtypp=iatypp}"
       javaType="List" ofType="com.rolandus.rolex.beans.SroisaBean"
       select="selectInvoiceCharges"/> 

Now if I add the parameter type to the select statement, a different result, 
but still an exception:

   <select id="selectInvoiceCharges"
           parameterType="int"
           resultType="com.rolandus.rolex.beans.SroisaBean" >
    select IAINVN, IATYPP, IAINYY, IACODE, IAAMOU
      from SROISA
     where iainvn = #{ihinvn} and iatypp = #{ihtypp}
    </select> 

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: 
org.apache.ibatis.reflection.ReflectionException: Error instantiating class 
java.lang.Integer with invalid types () or values (). Cause: 
java.lang.NoSuchMethodException: java.lang.Integer.<init>()
### The error may involve 
com.rolandus.rolex.beans.SroishInterface.selectInvoiceLines-Inline
### The error occurred while setting parameters
### Cause: org.apache.ibatis.reflection.ReflectionException: Error 
instantiating class java.lang.Integer with invalid types () or values (). 
Cause: java.lang.NoSuchMethodException: java.lang.Integer.<init>()

Please provide any additional information below.

I've Googled everywhere, read the manual, read this board looking for what I'm 
doing wrong.  I came up empty... 

Thanks in advance.

Original issue reported on code.google.com by odd.meth...@gmail.com on 22 Oct 2010 at 4:38

GoogleCodeExporter commented 9 years ago
This issue looks very similar to IBATIS-692 which was reported as fixed, but it 
seems the problem has resurfaced.  

Original comment by odd.meth...@gmail.com on 23 Oct 2010 at 1:33

GoogleCodeExporter commented 9 years ago
just a thought but can you try changing column="{ihinvn, ihtypp}" to 
column="{IHINVN, IHTYPP}"

Original comment by nathan.m...@gmail.com on 15 Sep 2011 at 3:18

GoogleCodeExporter commented 9 years ago
Seems this is related to #118.

Could you try again?

Original comment by eduardo.macarron on 15 Jan 2012 at 12:11