-
카테고리
-
세부 분야
백엔드
-
해결 여부
해결됨
h2 database 연동 관련 문제
21.08.02 11:47 작성 조회수 497
0
안녕하세요, 항상 유익한 강의 감사합니다!!
현재 안정화 버전으로 h2 데이터베이스를 설치하였으며, application.yml 생성 이후에 테스트 코드를 진행하게 되면 강의에서는 Hello 테이블이 생성되는걸 확인할 수 있는데 제가 진행하였을때는 테이블이 생성되지 않습니다..ㅠㅠ
로그를 확인해보니 트랜잭션 롤백이 발생하는 것 같은데 원인을 모르겠습니다..
관련 로그 첨부 드립니다.
2021-08-02 11:44:40.513 INFO 49375 --- [ main] study.querydsl.QuerydslApplicationTests : Starting QuerydslApplicationTests using Java 11.0.11 on moony.local with PID 49375 (started by moonbohyeon in /Users/moonbohyeon/IdeaProjects/querydsl) 2021-08-02 11:44:40.515 INFO 49375 --- [ main] study.querydsl.QuerydslApplicationTests : No active profile set, falling back to default profiles: default 2021-08-02 11:44:41.157 INFO 49375 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2021-08-02 11:44:41.182 INFO 49375 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 18 ms. Found 0 JPA repository interfaces. 2021-08-02 11:44:41.690 INFO 49375 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2021-08-02 11:44:41.859 INFO 49375 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2021-08-02 11:44:41.946 INFO 49375 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2021-08-02 11:44:41.989 INFO 49375 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final 2021-08-02 11:44:42.115 INFO 49375 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final} 2021-08-02 11:44:42.228 INFO 49375 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect 2021-08-02 11:44:42.766 DEBUG 49375 --- [ main] org.hibernate.SQL : drop table if exists hello CASCADE 2021-08-02 11:44:42.767 DEBUG 49375 --- [ main] org.hibernate.SQL : drop sequence if exists hibernate_sequence 2021-08-02 11:44:42.768 DEBUG 49375 --- [ main] org.hibernate.SQL : create sequence hibernate_sequence start with 1 increment by 1 2021-08-02 11:44:42.770 DEBUG 49375 --- [ main] org.hibernate.SQL : create table hello (id bigint not null, primary key (id)) 2021-08-02 11:44:42.775 INFO 49375 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] 2021-08-02 11:44:42.782 INFO 49375 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2021-08-02 11:44:42.988 WARN 49375 --- [ main] 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 2021-08-02 11:44:43.544 INFO 49375 --- [ main] study.querydsl.QuerydslApplicationTests : Started QuerydslApplicationTests in 3.427 seconds (JVM running for 4.713) 2021-08-02 11:44:43.666 INFO 49375 --- [ main] o.s.t.c.transaction.TransactionContext : Began transaction (1) for test context [DefaultTestContext@78f5c518 testClass = QuerydslApplicationTests, testInstance = study.querydsl.QuerydslApplicationTests@6b6c0b7c, testMethod = contextLoads@QuerydslApplicationTests, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@2f48b3d2 testClass = QuerydslApplicationTests, locations = '{}', classes = '{class study.querydsl.QuerydslApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@d23e042, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@69ee81fc, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@29f7cefd, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@9816741, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@36804139, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@6366ebe0], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true, 'org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@602aeb87]; rollback [true] 2021-08-02 11:44:43.756 DEBUG 49375 --- [ main] org.hibernate.SQL : call next value for hibernate_sequence 2021-08-02 11:44:43.969 DEBUG 49375 --- [ main] org.hibernate.SQL : insert into hello (id) values (?) 2021-08-02 11:44:43.973 DEBUG 49375 --- [ main] org.hibernate.SQL : select hello0_.id as id1_0_ from hello hello0_ 2021-08-02 11:44:44.025 INFO 49375 --- [ main] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test: [DefaultTestContext@78f5c518 testClass = QuerydslApplicationTests, testInstance = study.querydsl.QuerydslApplicationTests@6b6c0b7c, testMethod = contextLoads@QuerydslApplicationTests, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@2f48b3d2 testClass = QuerydslApplicationTests, locations = '{}', classes = '{class study.querydsl.QuerydslApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@d23e042, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@69ee81fc, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@29f7cefd, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@9816741, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@36804139, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@6366ebe0], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true, 'org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]] 2021-08-02 11:44:44.035 INFO 49375 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2021-08-02 11:44:44.036 INFO 49375 --- [ionShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down' 2021-08-02 11:44:44.036 DEBUG 49375 --- [ionShutdownHook] org.hibernate.SQL : drop table if exists hello CASCADE 2021-08-02 11:44:44.039 DEBUG 49375 --- [ionShutdownHook] org.hibernate.SQL : drop sequence if exists hibernate_sequence 2021-08-02 11:44:44.041 INFO 49375 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2021-08-02 11:44:44.044 INFO 49375 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
답변을 작성해보세요.
0
문보현
질문자2021.08.02
Test class, application.yml 첨부 드립니다!! 확인부탁드립니다ㅠㅠ
spring:
datasource:
#
url: jdbc:h2:tcp://localhost/~/querydsl
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
package study.querydsl;
import com.querydsl.jpa.impl.JPAQueryFactory;
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 org.springframework.test.annotation.Commit;
import org.springframework.transaction.annotation.Transactional;
import study.querydsl.entity.Hello;
import study.querydsl.entity.QHello;
import javax.persistence.EntityManager;
import java.util.List;
@SpringBootTest
@Transactional
class QuerydslApplicationTests {
@Autowired
EntityManager em;
@Test
void contextLoads() {
Hello hello = new Hello();
em.persist(hello);
JPAQueryFactory query = new JPAQueryFactory(em);
QHello qHello = QHello.hello; //Querydsl Q타입 동작 확인
Hello result = query
.selectFrom(qHello)
.fetchOne();
Assertions.assertThat(result).isEqualTo(hello);
//lombok 동작 확인 (hello.getId())
Assertions.assertThat(result.getId()).isEqualTo(hello.getId());
}
}
답변 3