인프런 커뮤니티 질문&답변
작성자 없음
작성자 정보가 삭제된 글입니다.
JPA와 DB 설정, 동작확인 관련 문의
작성
·
819
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.






none으로 변경 후 확인해도 같은 결과가 나오네요 ㅠㅠ