강의

멘토링

커뮤니티

Inflearn Community Q&A

quddbscjswow0010's profile image
quddbscjswow0010

asked

Spring DB Part 2 - Data Access Utilization Technology

MyBatis Application 2 - Configuration and Execution

테스트 할때 NullPointException이 납니다.ㅜ

Written on

·

566

0

JdbcTemplateV3Config로 테스트 하면 성공하는데MybatisConfig로 바꿔서 테스트 실행하면 id값이 null이어서 에러가 납니다.

create table item ( id bigint generated by default as identity, item_name varchar(10), price integer, quantity integer, primary key (id) )

이 로그도 잘찍히는데 저는 에러가 나네요..
테스트 실행하면 schema.sql에 있는 쿼리문이 실행되면서 id값이 auto_increment되고 save()실행하면 useGeneratedKeys="true" keyProperty="id" 여기서 자동증가된 id값이 매핑되는거 아닌가요?

그럼 sql파일에서 자동증가가 안되고 있다는거 같은데 구글에 여기저기 뒤져봐도 잘되네요..

답변 부탁드립니다.ㅠㅠ

spring.profiles.active=test
#spring.datasource.url=jdbc:h2:tcp://localhost/~/testcase
#spring.datasource.username=sa

테스트 프로퍼티 파일입니다.

spring

Answer 1

0

해결했습니다.

MyBatisConfig클래스에서 @RequiredArgConstructor써놓고 ItemMapper에

fianl 키워드를 안붙여 줬었네요..

quddbscjswow0010's profile image
quddbscjswow0010

asked

Ask a question