InvalidDataAccessApiUsageException

알파로그·2023년 3월 12일
0

Error

목록 보기
8/37
post-custom-banner

✏️ 문제의 코드

package jpabook.jpashop;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
class MemberRepositoryTest {

    @Autowired MemberRepository memberRepository;

    @Test
    void 회원정보저장 (){
        Member member = new Member();
        member.setId(1L);
        member.setUsername("memberA");

        Long save = memberRepository.save(member);
        Member memberId = memberRepository.find(member.getId());

        assertThat(memberId.getId()).isEqualTo(member.getId());
        assertThat(memberId.getUsername()).isEqualTo(member.getUsername());
    }
}

실행해보니 이러한 에러가 발생함

InvalidDataAccessApiUsageException:
	 No EntityManager with actual transaction available for current thread 
		- cannot reliably process 'persist' call

Test 실행시 transaction 에노테이션이 없어서 발생한 오류

❗️ EntityManager 를 통한 모든 data 변경은 transaction 안에서 이루어저야함

참고 : @Transaction

profile
잘못된 내용 PR 환영
post-custom-banner

0개의 댓글