Nested ResultMaps with ambiguous database columns

I have a couple of nested ResultMaps in iBatis that have the same database column names. This creates ambiguity and leads to incorrect results for different database tables.

For example, `

<sql namespace="Shipment">

       <resultMap id="consignment" class="com.model.Consignment">
              <result property="consignmentId" column="Consignment_cd" />
              <result property="shipmentCd" column="Shipment_cd" />
              <result property="shipmentUnit" column="Shipment_Unit" />
              <result property="location"  resultMap="Shipment.size" />
       </resultMap>

      <resultMap id="size" class="com.model.Size">
              <result property="consignmentId" column="Consignment_cd" />
              <result property="shipmentCd" column="Shipment_cd" />
              <result property="shipmentUnit" column="Shipment_Unit" />
      </resultMap>

    </sql>

      

`

Now, when I write my select query joining the size and consignment tables, I get the same values ​​for the code sent and the shipping unit, whereas there are different values ​​for the two columns in the database. Please note that I need both a Shipping Code and a Unit for both size levels and congruents pulled in the same request.

Can anyone help me solve this problem?

+3


source to share


1 answer


The only solution I have found for this problem is to prefix the column names with the table name or abbreviated name. Do you write the queries yourself?

Your choice will look like



select consignment.Shipment_cd as consignment_Shipment_cd, 
       size.Shipment_cd as size_Shipment_cd
from consignment
join size on whatever

      

And yes, it is quite heavy if you want to get a lot of stuff in the same query

+1


source







All Articles