소개
게시글
질문&답변
2023.05.08
QHello Test 에서 오류 확인 부탁드립니다.
H2 의 버젼을 1.4.199 에서 2.1.214 로 다시 올려서 해결하였습니다. 하루 전 질문에서는 스프링 부터 3.x 에서 2.1.214 실행시 붙지 않아, 1.4.199 로 내리니 해결되었는데, 지금 이부분은 다시 2.1.214 로 해야 동작하네요. 어제의 오류는 왜 발생안하는 지도 모르겠네요. 앞으로 어떤 오류가 날지도 모르겠고.. 스프링 부트와 h2 연결은 너무 불안 한 것 같습니다. JPA 공부중에 제일 어려운 부분이 스프링 부트와 h2 연결 같습니다. ( 저는 영한님의 모든 JPA 강의를 들었고, 항상 초기 2,3일 연결에 실패했던 것 같습니다. ) 다른 환경을 추천 해 주시거나, 명확한 매뉴얼 부탁드립니다.
- 0
- 4
- 776
질문&답변
2023.05.08
QHello Test 에서 오류 확인 부탁드립니다.
같은 문의가 여기도 한번 올라 온 것 같은데 해결되었는 지요? https://www.inflearn.com/questions/701235/test%EC%98%A4%EB%A5%98
- 0
- 4
- 776
질문&답변
2023.05.08
QHello Test 에서 오류 확인 부탁드립니다.
추가 된 것은 Hello class 를 만들었고, package study.querydsl.entity; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import lombok.Getter; import lombok.Setter; @Entity @Getter @Setter public class Hello { @Id @GeneratedValue private Long id ; } QHello 가 만들어 졌고, package study.querydsl.entity; import static com.querydsl.core.types.PathMetadataFactory.*; import com.querydsl.core.types.dsl.*; import com.querydsl.core.types.PathMetadata; import javax.annotation.processing.Generated; import com.querydsl.core.types.Path; /** * QHello is a Querydsl query type for Hello */ @Generated("com.querydsl.codegen.DefaultEntitySerializer") public class QHello extends EntityPathBase { private static final long serialVersionUID = 1910216155L; public static final QHello hello = new QHello("hello"); public final NumberPath id = createNumber("id", Long.class); public QHello(String variable) { super(Hello.class, forVariable(variable)); } public QHello(Path path) { super(path.getType(), path.getMetadata()); } public QHello(PathMetadata metadata) { super(Hello.class, metadata); } }테스트 코드는 아래와 같습니다. package study.querydsl; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; 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 static org.assertj.core.api.Assertions.*; @SpringBootTest @Transactional @Commit class QuerydslApplicationTests { @Autowired EntityManager em; @Test void contextLoads() { Hello hello = new Hello(); em.persist(hello); JPAQueryFactory query = new JPAQueryFactory(em); QHello qHello = QHello.hello; Hello result = query.selectFrom(qHello).fetchOne(); assertThat(result).isEqualTo(hello); assertThat(result.getId()).isEqualTo(hello.getId()); } } 오류 코드는 아래가 핵심 같은데요. Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=study.querydsl.entity.Hello]Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=study.querydsl.entity.Hello]
- 0
- 4
- 776
질문&답변
2023.05.07
unit Test 는 성공했다고 나옵니다만, h2 콘솔에서 Hello table 이 생성되지 않았습니다.
h2 를 2.1.214 버전을 제거 하고, 1.4.199 버젼으로 다운그레이드 하여 성공하였습니다. 지난번 다른 수업에서는 1.4.199 는 실패하고, 2.1.214 만 성공했었는데, 어렵네요.
- 0
- 3
- 758
질문&답변
2023.05.07
unit Test 는 성공했다고 나옵니다만, h2 콘솔에서 Hello table 이 생성되지 않았습니다.
들여 쓰기를 같이 하여 테스트 해 보았습니다. 실행해 봤는데, h2 를 끄면 오류를 내고 h2 를 켰을 때 오류를 내지 않는 것으로 봐서 정상 연결한 것 같은데, 테스트 시작시 연결로그도 없네요. 아래와 같이 나오고 h2 콘솔에서는 hello 테이블이 추가되지 않습니다. 2023-05-07 19:21:57.872 INFO 17015 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...2023-05-07 19:21:57.946 INFO 17015 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.2023-05-07 19:21:58.006 INFO 17015 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]2023-05-07 19:21:58.067 INFO 17015 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.9.Final}2023-05-07 19:21:58.260 INFO 17015 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}2023-05-07 19:21:58.407 INFO 17015 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect2023-05-07 19:21:59.091 DEBUG 17015 --- [ main] org.hibernate.SQL : drop table hello if exists2023-05-07 19:21:59.095 DEBUG 17015 --- [ main] org.hibernate.SQL : drop table member if exists2023-05-07 19:21:59.096 DEBUG 17015 --- [ main] org.hibernate.SQL : drop table team if exists2023-05-07 19:21:59.097 DEBUG 17015 --- [ main] org.hibernate.SQL : drop sequence if exists hibernate_sequence2023-05-07 19:21:59.100 DEBUG 17015 --- [ main] org.hibernate.SQL : create sequence hibernate_sequence start with 1 increment by 12023-05-07 19:21:59.103 DEBUG 17015 --- [ main] org.hibernate.SQL : create table hello (id bigint not null, primary key (id))2023-05-07 19:21:59.105 DEBUG 17015 --- [ main] org.hibernate.SQL : create table member (member_id bigint not null, age integer not null, username varchar(255), team_id bigint, primary key (member_id))2023-05-07 19:21:59.107 DEBUG 17015 --- [ main] org.hibernate.SQL : create table team (team_id bigint not null, name varchar(255), primary key (team_id))2023-05-07 19:21:59.110 DEBUG 17015 --- [ main] org.hibernate.SQL : alter table member add constraint FKcjte2jn9pvo9ud2hyfgwcja0k foreign key (team_id) references team2023-05-07 19:21:59.115 INFO 17015 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]2023-05-07 19:21:59.121 INFO 17015 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'2023-05-07 19:21:59.349 WARN 17015 --- [ 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 warning2023-05-07 19:21:59.547 INFO 17015 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'2023-05-07 19:21:59.806 INFO 17015 --- [ main] study.querydsl.QuerydslApplicationTests : Started QuerydslApplicationTests in 8.197 seconds (JVM running for 8.992)2023-05-07 19:21:59.891 INFO 17015 --- [ main] o.s.t.c.transaction.TransactionContext : Began transaction (1) for test context [DefaultTestContext@3e62d773 testClass = QuerydslApplicationTests, testInstance = study.querydsl.QuerydslApplicationTests@796fe2b5, testMethod = contextLoads@QuerydslApplicationTests, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@4ef74c30 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.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@7dcf94f8, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@f5958c9, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@5bda8e08, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@3d285d7e], 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]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@1031c1a0]; rollback [false]2023-05-07 19:21:59.978 DEBUG 17015 --- [ main] org.hibernate.SQL : call next value for hibernate_sequence2023-05-07 19:22:00.180 DEBUG 17015 --- [ main] org.hibernate.SQL : insert into hello (id) values (?)2023-05-07 19:22:00.185 DEBUG 17015 --- [ main] org.hibernate.SQL : select hello0_.id as id1_0_ from hello hello0_2023-05-07 19:22:00.246 INFO 17015 --- [ main] o.s.t.c.transaction.TransactionContext : Committed transaction for test: [DefaultTestContext@3e62d773 testClass = QuerydslApplicationTests, testInstance = study.querydsl.QuerydslApplicationTests@796fe2b5, testMethod = contextLoads@QuerydslApplicationTests, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@4ef74c30 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.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@7dcf94f8, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@f5958c9, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@5bda8e08, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@3d285d7e], 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]]2023-05-07 19:22:00.255 INFO 17015 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'2023-05-07 19:22:00.255 INFO 17015 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'2023-05-07 19:22:00.256 INFO 17015 --- [extShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'2023-05-07 19:22:00.256 DEBUG 17015 --- [extShutdownHook] org.hibernate.SQL : drop table hello if exists2023-05-07 19:22:00.258 DEBUG 17015 --- [extShutdownHook] org.hibernate.SQL : drop table member if exists2023-05-07 19:22:00.260 DEBUG 17015 --- [extShutdownHook] org.hibernate.SQL : drop table team if exists2023-05-07 19:22:00.262 DEBUG 17015 --- [extShutdownHook] org.hibernate.SQL : drop sequence if exists hibernate_sequence2023-05-07 19:22:00.264 INFO 17015 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...2023-05-07 19:22:09.295 INFO 17015 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
- 0
- 3
- 758