> For the complete documentation index, see [llms.txt](https://flamme1004.gitbook.io/flamme-dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://flamme1004.gitbook.io/flamme-dev/info-1/framework/spring/springetc/mybatis/1-1-mapping-null.md).

# 1:1 Mapping시 Null

2020/07/17

```
<resultMap id=”get-product-result” class=”com.ibatis.example.Product”>
<result property=”id” column=”PRD_ID”/>
<result property=”description” column=”PRD_DESCRIPTION”/>
<result property=”category.id” column=”CAT_ID” />
<result property=”category.description” column=”CAT_DESCRIPTION” />
</resultMap>
<statement id=”getProduct” parameterClass=”int” resultMap=”get-product-result”>
select * from PRODUCT, CATEGORY where PRD_CAT_ID=CAT_ID and PRD_ID = #value#
</statement>
```

category.id를 넣었는데 NullPointerException이 일어나는 이유는 뭘까?

```
public class Product{
    private String id;
    private String description;
    private Category category;
    ...
}
```

여기서 문제가 있다.

바로 Category에 대한 새로운 생성자를 만들어 주지 않았기 때문이다.

```
public class Product{
    private String id;
    private String description;
    private Category category = new Category();
    ...
}
```

&#x20;이렇게 되어야한다.

&#x20;내 2시간..

Ref. <http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_ko.pdf>
