Mysql

Mysql_ Mybatis ResultMap ....

JunsC 2024. 9. 11. 12:06
728x90

mysql 에서 셀렉트 리턴값은 제대로 나오고 있는데 Springboot mybatis 에서는 계속 1개밖에 안나온다..

분명 쿼리는 같고 이상없는걸 확인했는데도 이상하게 중복된 결과값이 겹친듯한 느낌으로 1개밖에 안나온다...

음...

 

우선 코드를 보면 

 

<resultMap id="Follow" type="Follow">
        <result property="type" column="type" />
        <association property="partner" javaType="User">
            <result property="user_uuid" column="partner_user_uuid" />
            <result property="thumbnail" column="partner_thumbnail" />
            <result property="grade" column="partner_grade" />
            <result property="name" column="partner_name" />
            <result property="gender" column="partner_gender" />
            <result property="age" column="partner_age" />
        </association>
        <association property="user" javaType="User">
            <result property="user_uuid" column="user_uuid" />
            <result property="thumbnail" column="thumbnail" />
            <result property="grade" column="grade" />
            <result property="name" column="name" />
            <result property="gender" column="gender" />
            <result property="age" column="age" />
        </association>
    </resultMap>

 

이렇게 ResultMap 으로 빈형식으로 만들고 대입하는 구조로 진행하고 있었다.

mysql 에서의 리턴 컬럼들과 맞춰서 작업하고 있어서 중복된 부분에 대해서는 전혀 필터없이 전부 리턴값들이 잘 나올꺼라 생각했는데 

그게 아니였다..

확인해보니 

<association ==>   이 부분에서 뭔가 문제가 있는거 같았다.

뭔가 중복관련된 문제인듯 보여서 구글링을 시작했다..

 

ResultMap 중복 <== 키워드를 이렇게 ㅋㅋ 

 

수많은 자료조사중 
https://m.blog.naver.com/qhdqhdekd261/221521101966

 

[MyBatis] association(연상, 연관)

Association(연상, 연관) MyBatis(이하 마이바티스)로 resultMap을 작성하다가 문제에 직면했다. 다른 ...

blog.naver.com

 

이 사이트에서 뭔가 색다른 방법을 알게 되었다.

 

그래서 ResultMap 에 대한 중복문제는 association 이라는 구문에서 뭔가 작업을 해주어야 하는구나 라는것을 직감하게 되었고

다른 구조로 작업을 하였다.

 

 

<resultMap id="Follow" type="Follow">
        <result property="type" column="type" />
        <association property="user" column="user_uuid" javaType="User" select="findUser" />
        <association property="partner" column="partner_user_uuid" javaType="User" select="findUser" />
    </resultMap>

 

이렇게 바꾸었더니.... hasmap 관련 중복 키 문제를 해결하게 됐다. !!!!!!!

728x90

'Mysql' 카테고리의 다른 글

Mysql 암호화  (0) 2024.06.09
Mysql  (0) 2024.02.04
"이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."