h2 database 연동 관련 문제
해결된 질문
683
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.
답변 3
1
김영한
안녕하세요. 보현님
application.yml은 띄어쓰기가 매우 중요합니다.
메뉴얼과 같이 띄어쓰기는 맞추어주세요. 띄어쓰기 2칸 단위로 계층이 동작합니다.
감사합니다.
0
문보현
띄어쓰기가 문제였습니다!!
빠른 답변 감사합니다ㅎㅎ 다음부턴 좀 더 주의하도록 하겠습니다
0
문보현
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());
}
}
0
David
안녕하세요. 문보현님, 공식 서포터즈 David입니다.
.
올려주신 로그로만 원인을 알기 어렵습니다.
Test class, application.yml 등 내용을 캡쳐해서 올려주세요.
.
감사합니다.
join에대해 질문드립니다.
SpringBoot 4.X에서의 Querydsl 설정
querydsl 오픈소스에 대한 질문
예제에서의 카운트 쿼리에서 join문과 where문은 필요없지 않나요?
Querydsl 6.X버전에 대해서 어떻게 생각하시나요?
여러 테이블 조인하여 통계치를 구하고자 할 때 어떤 방법이 더 효율적일까요
fetchResults()는 더이상 권장되지 않는다는데 맞나요?
querydsl sum() 메서드 없어요.
build 디렉터리 생성
자바 ORM 표준 JPA 프로그래밍 - 기본편 듣고 바로 학습해도 괜찮을까요?
현재 Querydsl에서 from절 서브쿼리를 지원하나요?
오타 제보 드립니다.
벌크 연산과 flush, clear
Run As Intellij 로 변경시 Q타입 import 불가
QHello import하기 문제 발생
등록된 함수 보는법(H2Dialect) 질문
5.0부터 Querydsl은 향후 fetchCount() , fetchResult() 를 지원하지 않기로 결정했다고 하는데 이에 맞는 강의
[환경설정 PDF 부트 3.0이후 설명 질문] build.gradle에 compileQuerydsl을 정의하지 않은 상태에서 Gradle->Tasks->other->compileQuerydsl을 클릭하라고 하는 이유가 무엇인가요??
querydsl 설정 문제
quey dsl 설정부분
count 쿼리 관련 질문입니다!
stringtemplate를 이용하여 where절 검색 방법 질문 드립니다.
답변부탁드리겠습니다.
(OrderSpecifier)관련 내용 어디있을가요