mybatis 에서 association를 사용하면 중복된 값이 출력되지 않는 문제가 있다.
<resultMap type="kr.co.auction.schema.arche_apisvc.ConfirmingReceiptT" id="ConfirmingReceiptT" >
<result property="receiptStatus" column="RECEIPTSTATUS" />
<result property="sellingType" column="SELLINGTYPE" />
<result property="paymentTimeLimit" column="PAYMENTTIMELIMIT" />
<association property="orderBase" javaType="kr.co.auction.schema.arche_apisvc.OrderBaseT" >
<result property="itemID" column="ITEMID" />
<result property="orderNo" column="ORDERNO" />
<result property="itemName" column="ITEMNAME" />
<result property="awardQty" column="AWARDQTY" />
<result property="awardAmount" column="AWARDAMOUNT" />
<result property="deliveryFeeAmount" column="DELIVERYFEEAMOUNT" />
<result property="buyerName" column="BUYERNAME" />
<result property="buyerID" column="BUYERID" />
<result property="groupOrderSeqno" column="GROUPORDERSEQNO" />
<result property="requestOption" column="REQUESTOPTION" />
<result property="requestOptionPrice" column="REQUESTOPTIONPRICE" />
<result property="sellerStockCode" column="SELLERSTOCKCODE" />
<result property="orderDate" column="ORDERDATE" />
</association>
<association property="addressBase" javaType="kr.co.auction.schema.arche_apisvc.AddressBaseT" >
<result property="name" column="NAME" />
<result property="tel" column="TEL" />
<result property="mobileTel" column="MOBILETEL" />
<result property="email" column="EMAIL" />
<result property="postNo" column="POSTNO" />
<result property="addressPost" column="ADDRESSPOST" />
<result property="addressDetail" column="ADDRESSDETAIL" />
<result property="addressRoadName" column="ADDRESSROADNAME" />
</association>
</resultMap>
예를 들어 위와 같은 resultMap이 있을 경우, RECEIPTSTATUS, SELLINGTYPE, PAYMENTTIMELIMIT 3개의 필드의 내용이
모두 같을 경우는 총 row가 10개든, 100개든 한개의 row만 출력된다.
검색하면 <result 를 <id 로 바꾸라는 내용이 있는데, 이건 중복체크에 사용할 필드를 지정하는 것이다. <id로 지정시에는 해당 필드만 중복체크에 사용한다.
<result를 사용하면 나처럼 모두 비교한다.
나의 경우는 id 역할을 하는 필드(ex.primari key)가 없어서 문제가 된다.
해결책은
여기서 찾았다.
association을 쓰지 말라는 거다.
어떻게 보면 더 깔끔한 것 같기도 하다.
아무튼 아래와 같이 변경하면 중복된 내용을 제외하고 않고 전체를 잘 가져온다.
<resultMap type="kr.co.auction.schema.arche_apisvc.ConfirmingReceiptT" id="ConfirmingReceiptT" >
<result property="receiptStatus" column="RECEIPTSTATUS" />
<result property="sellingType" column="SELLINGTYPE" />
<result property="paymentTimeLimit" column="PAYMENTTIMELIMIT" />
<result property="orderBase.itemID" column="ITEMID" />
<result property="orderBase.orderNo" column="ORDERNO" />
<result property="orderBase.itemName" column="ITEMNAME" />
<result property="orderBase.awardQty" column="AWARDQTY" />
<result property="orderBase.awardAmount" column="AWARDAMOUNT" />
<result property="orderBase.deliveryFeeAmount" column="DELIVERYFEEAMOUNT" />
<result property="orderBase.buyerName" column="BUYERNAME" />
<result property="orderBase.buyerID" column="BUYERID" />
<result property="orderBase.groupOrderSeqno" column="GROUPORDERSEQNO" />
<result property="orderBase.requestOption" column="REQUESTOPTION" />
<result property="orderBase.requestOptionPrice" column="REQUESTOPTIONPRICE" />
<result property="orderBase.sellerStockCode" column="SELLERSTOCKCODE" />
<result property="orderBase.orderDate" column="ORDERDATE" />
<result property="addressBase.name" column="NAME" />
<result property="addressBase.tel" column="TEL" />
<result property="addressBase.mobileTel" column="MOBILETEL" />
<result property="addressBase.email" column="EMAIL" />
<result property="addressBase.postNo" column="POSTNO" />
<result property="addressBase.addressPost" column="ADDRESSPOST" />
<result property="addressBase.addressDetail" column="ADDRESSDETAIL" />
<result property="addressBase.addressRoadName" column="ADDRESSROADNAME" />
</resultMap>