JPA와 DB 설정, 동작확인 관련 문의
831
작성자 없음
작성한 질문수 0
JPA와 DB 설정, 동작확인 강의를 듣는 도중 문제가 발생하여 질문드립니다.
MemberRepositoryTest클래스의 testMember메소드에 Transactional어노테이션을 추가하기 전에 에러가 떠야하는 걸로 알고있는데 에러가 따로 발생하지 않고 잘 실행이 되었으며 db에 Member테이블이 생성된 것을 확인할 수 있었습니다.
그 후 Transactional어노테이션을 추가하여 재실행한 결과 별다른 오류 없이 Run되었지만, Member테이블에는 값이 여전히 들어가지 않은 모습을 확인할 수 있었습니다.
연결은 된 것 같지만 값이 안들어가는 이유를 모르겠어서 질문드립니다.

package jpabook.jpashop;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
public class MemberRepositoryTest {
@Autowired MemberRepository memberRepository;
@Test
@Transactional
@Rollback(value = false)
public void testMember() throws Exception {
//given
Member member = new Member();
member.setUsername("memberA");
//when
Long savedId = memberRepository.save(member);
Member findMember = memberRepository.find(savedId);
//then
Assertions.assertThat(findMember.getId()).isEqualTo(member.getId());
Assertions.assertThat(findMember.getUsername()).isEqualTo(member.getUsername());
}
}
package jpabook.jpashop;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Repository
public class MemberRepository {
@PersistenceContext
private EntityManager em;
public Long save(Member member) {
em.persist(member);
return member.getId();
}
public Member find(Long id) {
return em.find(Member.class, id);
}
}
package jpabook.jpashop;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
@Getter @Setter
public class Member {
@Id @GeneratedValue
private Long id;
private String username;
}
spring:
datasource:
url: jdbc:h2:tcp://localhost/~/jpashop
username: sa
password:
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: create
properties:
hibernate:
# show_sql: true
format_sql: true
logging:
level:
org.hibernate.SQL: debug
# org.hibernate.type: trace
2022-02-23 12:15:07.939 INFO 29996 --- [ restartedMain] jpabook.jpashop.JpashopApplication : No active profile set, falling back to default profiles: default
2022-02-23 12:15:07.961 INFO 29996 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-02-23 12:15:07.961 INFO 29996 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-02-23 12:15:08.181 INFO 29996 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-02-23 12:15:08.186 INFO 29996 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 2 ms. Found 0 JPA repository interfaces.
2022-02-23 12:15:08.395 INFO 29996 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-02-23 12:15:08.399 INFO 29996 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-02-23 12:15:08.399 INFO 29996 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-02-23 12:15:08.440 INFO 29996 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-02-23 12:15:08.440 INFO 29996 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 479 ms
2022-02-23 12:15:08.453 INFO 29996 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-02-23 12:15:08.471 INFO 29996 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-02-23 12:15:08.475 INFO 29996 --- [ restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:tcp://localhost/~/jpashop'
2022-02-23 12:15:08.510 INFO 29996 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-02-23 12:15:08.525 INFO 29996 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.4.Final
2022-02-23 12:15:08.566 INFO 29996 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-02-23 12:15:08.596 INFO 29996 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-02-23 12:15:08.764 DEBUG 29996 --- [ restartedMain] org.hibernate.SQL :
drop table if exists member CASCADE
2022-02-23 12:15:08.766 DEBUG 29996 --- [ restartedMain] org.hibernate.SQL :
drop sequence if exists hibernate_sequence
2022-02-23 12:15:08.767 DEBUG 29996 --- [ restartedMain] org.hibernate.SQL : create sequence hibernate_sequence start with 1 increment by 1
2022-02-23 12:15:08.768 DEBUG 29996 --- [ restartedMain] org.hibernate.SQL :
create table member (
id bigint not null,
username varchar(255),
primary key (id)
)
2022-02-23 12:15:08.769 INFO 29996 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-02-23 12:15:08.772 INFO 29996 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-02-23 12:15:08.806 WARN 29996 --- [ restartedMain] 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
2022-02-23 12:15:08.872 INFO 29996 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2022-02-23 12:15:08.933 INFO 29996 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2022-02-23 12:15:08.953 INFO 29996 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-02-23 12:15:08.959 INFO 29996 --- [ restartedMain] jpabook.jpashop.JpashopApplication : Started JpashopApplication in 1.151 seconds (JVM running for 1.595)
2022-02-23 12:24:38.447 WARN 29996 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Retrograde clock change detected (housekeeper delta=29s827ms), soft-evicting connections from pool.
답변 1
OrderServiceTest 상문주문 테스트 시 update 쿼리 문의
0
39
1
sdk 설정 오류
0
82
2
오탈자 - @Transactional
0
75
1
src/test/resources 테스트 경로 문제
0
74
1
상품 등록후 H2 db 출력 순서 바꿀 수 있나요?
0
74
1
MemberRepositoryTest 실행오류
0
98
1
boot 4.x >>> trasasction rolled back log & p6spy(영한님, 수업 자료 업데이트 해주시면 감사하겠습니다!!)
1
204
2
강의 마지막 QueryDSL 사용 부분 질문있습니다
1
160
2
클라이언트에서 isbn과 author 수정 요청을 한 경우에 대해 질문드립니다.
0
61
1
도메인 모델 패턴 vs 트랜잭션 스크립트 패턴
0
89
1
기본 생성자
0
69
1
h2 DB 연결시 jdbc url 변경 이유가 궁금합니다.
0
109
1
멤버서비스테스트 부분에서 막힙니다.
0
188
4
실무에서도 EntityManager를 이용해서 많이 작업하는 편일까요?
0
130
1
초반에 h2 다운로드 과정 꼭 필요한가요?
0
134
2
자신 필드에도 get으로 접근하는 이유가 있을까요?
0
125
1
24분 27초 연관관계 편의 메서드 위치
0
120
1
단건 주문만 가능하게 한건 의도한 부분이신가요?
0
119
2
빌드 툴, Gradle
0
71
1
h2연결은 된 것 같은데 엔티티 테이블까지 작성 후 확인해보아도 테이블이 안보입니다
0
85
2
Repository에서 EntityManager 주입 방식 차이
0
100
1
롬복과 사용자 정의 setter 메서드
0
79
1
주문 목록 조회 fetch join 질문드립니다
0
93
1
dirty checking 질문드립니다.
0
91
1





