인프런 커뮤니티 질문&답변

초보개발자님의 프로필 이미지
초보개발자

작성한 질문수

실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발

JPA와 DB 설정, 동작확인

강의 콘솔처럼 rolled back 기록이 안 보이네요

작성

·

163

0

@ExtendWith(SpringExtension.class)
@SpringBootTest
class MemberRepositoryTest {

    @Autowired MemberRepository memberRepository;

    @Test
    @Transactional
    public void testMember() throws Exception {
        //given
        Member member = new Member();
        member.setUsername("memberA");

        //when
        Long saveId = memberRepository.save(member);
        Member findMember = memberRepository.find(saveId);

        //then
        Assertions.assertThat(findMember.getId()).isEqualTo(member.getId());
        Assertions.assertThat(findMember.getUsername()).isEqualTo(member.getUsername());

        
    }
2024-08-27T08:46:11.488+09:00  INFO 20440 --- [    Test worker] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2024-08-27T08:46:11.607+09:00  INFO 20440 --- [    Test worker] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection conn0: url=jdbc:h2:tcp://localhost/~/jpashop user=SA
2024-08-27T08:46:11.610+09:00  INFO 20440 --- [    Test worker] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2024-08-27T08:46:12.826+09:00  INFO 20440 --- [    Test worker] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2024-08-27T08:46:12.846+09:00 DEBUG 20440 --- [    Test worker] org.hibernate.SQL                        : 
    drop table if exists member cascade 
2024-08-27T08:46:12.853+09:00 DEBUG 20440 --- [    Test worker] org.hibernate.SQL                        : 
    drop sequence if exists member_seq
2024-08-27T08:46:12.860+09:00 DEBUG 20440 --- [    Test worker] org.hibernate.SQL                        : 
    create sequence member_seq start with 1 increment by 50
2024-08-27T08:46:12.866+09:00 DEBUG 20440 --- [    Test worker] org.hibernate.SQL                        : 
    create table member (
        id bigint not null,
        username varchar(255),
        primary key (id)
    )
2024-08-27T08:46:12.872+09:00  INFO 20440 --- [    Test worker] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-08-27T08:46:13.228+09:00  WARN 20440 --- [    Test worker] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2024-08-27T08:46:13.272+09:00  INFO 20440 --- [    Test worker] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
2024-08-27T08:46:13.987+09:00  INFO 20440 --- [    Test worker] jpabook.jpashop.MemberRepositoryTest     : Started MemberRepositoryTest in 6.47 seconds (process running for 8.794)
WARNING: A Java agent has been loaded dynamically (C:\gradle\caches\modules-2\files-2.1\net.bytebuddy\byte-buddy-agent\1.14.19\154da3a65b4f4a909d3e5bdec55d1b2b4cbb6ce1\byte-buddy-agent-1.14.19.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
2024-08-27T08:46:14.774+09:00 DEBUG 20440 --- [    Test worker] org.hibernate.SQL                        : 
    select
        next value for member_seq
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2024-08-27T08:46:14.914+09:00  INFO 20440 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2024-08-27T08:46:14.918+09:00  INFO 20440 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2024-08-27T08:46:14.933+09:00  INFO 20440 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
> Task :test
BUILD SUCCESSFUL in 26s
4 actionable tasks: 1 executed, 3 up-to-date
오전 8:46:15: Execution finished ':test --tests "jpabook.jpashop.MemberRepositoryTest.testMember"'.

Transactional 애노테이션을 붙였는데 롤백얘기가 안보이네요... JUnit5로 해서 차이가 있는걸까요?

답변 2

0

안녕하세요. 초보개발자님, 공식 서포터즈 OMG입니다.

AI답변을 참고해주세요. 해결이 안될 경우 댓글 남겨주세요 😀

감사합니다.

2024-08-28T20:45:53.098+09:00 DEBUG 15060 --- [           main] org.hibernate.SQL                        : 
    select
        m1_0.member_id,
        m1_0.city,
        m1_0.street,
        m1_0.zipcode,
        m1_0.name 
    from
        member m1_0 
    where
        m1_0.name=?
2024-08-28T20:45:53.104+09:00 TRACE 15060 --- [           main] org.hibernate.orm.jdbc.bind              : binding parameter (1:VARCHAR) <- [kim]
2024-08-28T20:45:53.112+09:00  INFO 15060 --- [           main] p6spy                                    : #1724845553112 | took 7ms | statement | connection 3| url jdbc:h2:tcp://localhost/~/jpashop
select m1_0.member_id,m1_0.city,m1_0.street,m1_0.zipcode,m1_0.name from member m1_0 where m1_0.name=?
select m1_0.member_id,m1_0.city,m1_0.street,m1_0.zipcode,m1_0.name from member m1_0 where m1_0.name='kim';
2024-08-28T20:45:53.118+09:00 DEBUG 15060 --- [           main] org.hibernate.SQL                        : 
    select
        next value for member_seq
2024-08-28T20:45:53.120+09:00  INFO 15060 --- [           main] p6spy                                    : #1724845553120 | took 0ms | statement | connection 3| url jdbc:h2:tcp://localhost/~/jpashop
select next value for member_seq
select next value for member_seq;
2024-08-28T20:45:53.204+09:00  INFO 15060 --- [           main] p6spy                                    : #1724845553204 | took 0ms | rollback | connection 3| url jdbc:h2:tcp://localhost/~/jpashop

;
2024-08-28T20:45:53.244+09:00  INFO 15060 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2024-08-28T20:45:53.250+09:00  INFO 15060 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2024-08-28T20:45:53.262+09:00  INFO 15060 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

Process finished with exit code 0



혹시 rolled back 이 부분 로그 표현 방식이 변경되었나요?
rollback만 찾았네요

0

안녕하세요, 인프런 AI 인턴입니다.

초보개발자님께서 질문하신 내용은 JUnit5와 @Transactional 어노테이션을 사용하여 강의에서처럼 롤백이 잘 되고 있는지 확인하려고 하는데, 롤백 관련 로그가 보이지 않는 문제에 관한 것입니다.

이와 유사한 상황에 대해 다룬 기존 질문에서는, 스프링 6 이후 버전부터는 롤백 관련 로그가 변경되었다는 점을 다루고 있습니다. 스프링 부트의 버전이나 로그 설정에 따라 롤백과 관련된 출력 로그가 달라질 수 있으며, 경우에 따라서는 특정 로그 레벨(DEBUGTRACE 등)에서만 롤백 로그가 보일 수 있습니다.

해당 내용은 다음 링크에서 확인해볼 수 있습니다:
- Transactional 했는데 롤백 문구가 안 떠요

간단한 요약으로, @Transactional 어노테이션이 붙어 있더라도 로그 레벨 설정에 따라 롤백 관련 로그가 다르게 출력될 수 있습니다. 따라서 application.yaml 또는 application.properties 파일에서 로그 레벨을 조절해보시기 바랍니다. 예를 들어, 다음과 같은 설정을 해볼 수 있습니다:

logging:
  level:
    root: trace # 또는 debug

이 설정 후 다시 테스트를 실행해 보시면 롤백 관련 로그를 확인할 수 있을 것입니다.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.

현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏

추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

초보개발자님의 프로필 이미지
초보개발자

작성한 질문수

질문하기