인프런 커뮤니티 질문&답변

김주영님의 프로필 이미지
김주영

작성한 질문수

실전! Querydsl

스프링 부트 설정 - JPA, DB

Hello 테이블 생성 안됨..

해결된 질문

작성

·

453

·

수정됨

1

안녕하세요..

 

Hello Table이 생성이 안돼서 질문 드립니다.

 

  • 모든 코드는 강의자료에 있는 코드를 복붙했습니다. (에러가 나서 ..)

 test코드를 돌려보면 에러는 안나는데 h2db테이블에서 생성이 안됩니다.

에러 코드


> Task :compileJava UP-TO-DATE
> Task :processResources
> Task :classes
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :test
15:47:24.714 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [study.querydsl.QuerydslApplicationTests]: QuerydslApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
15:47:24.762 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration study.querydsl.QuerydslApplication for test class study.querydsl.QuerydslApplicationTests

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.0)

2024-01-02T15:47:24.972+09:00  INFO 14318 --- [    Test worker] s.querydsl.QuerydslApplicationTests      : Starting QuerydslApplicationTests using Java 17.0.6 with PID 14318 (started by gaheechoi in /Users/gaheechoi/Desktop/휴학/백앤드/querydsl)
2024-01-02T15:47:24.973+09:00  INFO 14318 --- [    Test worker] s.querydsl.QuerydslApplicationTests      : No active profile set, falling back to 1 default profile: "default"
2024-01-02T15:47:25.274+09:00  INFO 14318 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-01-02T15:47:25.285+09:00  INFO 14318 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 0 JPA repository interfaces.
2024-01-02T15:47:25.532+09:00  INFO 14318 --- [    Test worker] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2024-01-02T15:47:25.557+09:00  INFO 14318 --- [    Test worker] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.3.1.Final
2024-01-02T15:47:25.573+09:00  INFO 14318 --- [    Test worker] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled
2024-01-02T15:47:25.685+09:00  INFO 14318 --- [    Test worker] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2024-01-02T15:47:25.700+09:00  INFO 14318 --- [    Test worker] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2024-01-02T15:47:25.796+09:00  INFO 14318 --- [    Test worker] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced user=SA
2024-01-02T15:47:25.797+09:00  INFO 14318 --- [    Test worker] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2024-01-02T15:47:25.908+09:00  INFO 14318 --- [    Test worker] p6spy                                    : #1704178045908 | took 3ms | statement | connection 1| url jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced
select * from INFORMATION_SCHEMA.SEQUENCES
select * from INFORMATION_SCHEMA.SEQUENCES;
2024-01-02T15:47:26.178+09:00  INFO 14318 --- [    Test worker] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2024-01-02T15:47:26.186+09:00 DEBUG 14318 --- [    Test worker] org.hibernate.SQL                        : drop table if exists hello cascade 
2024-01-02T15:47:26.187+09:00  INFO 14318 --- [    Test worker] p6spy                                    : #1704178046187 | took 0ms | statement | connection 2| url jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced
drop table if exists hello cascade 
drop table if exists hello cascade ;
2024-01-02T15:47:26.187+09:00 DEBUG 14318 --- [    Test worker] org.hibernate.SQL                        : drop sequence if exists hello_seq
2024-01-02T15:47:26.187+09:00  INFO 14318 --- [    Test worker] p6spy                                    : #1704178046187 | took 0ms | statement | connection 2| url jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced
drop sequence if exists hello_seq
drop sequence if exists hello_seq;
2024-01-02T15:47:26.189+09:00 DEBUG 14318 --- [    Test worker] org.hibernate.SQL                        : create sequence hello_seq start with 1 increment by 50
2024-01-02T15:47:26.191+09:00  INFO 14318 --- [    Test worker] p6spy                                    : #1704178046191 | took 1ms | statement | connection 3| url jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced
create sequence hello_seq start with 1 increment by 50
create sequence hello_seq start with 1 increment by 50;
2024-01-02T15:47:26.192+09:00 DEBUG 14318 --- [    Test worker] org.hibernate.SQL                        : create table hello (id bigint not null, primary key (id))
2024-01-02T15:47:26.194+09:00  INFO 14318 --- [    Test worker] p6spy                                    : #1704178046194 | took 1ms | statement | connection 3| url jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced
create table hello (id bigint not null, primary key (id))
create table hello (id bigint not null, primary key (id));
2024-01-02T15:47:26.195+09:00  INFO 14318 --- [    Test worker] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-01-02T15:47:26.268+09:00  WARN 14318 --- [    Test worker] 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
2024-01-02T15:47:26.478+09:00  INFO 14318 --- [    Test worker] s.querydsl.QuerydslApplicationTests      : Started QuerydslApplicationTests in 1.645 seconds (process running for 2.13)
2024-01-02T15:47:26.801+09:00 DEBUG 14318 --- [    Test worker] org.hibernate.SQL                        : select next value for hello_seq
2024-01-02T15:47:26.803+09:00  INFO 14318 --- [    Test worker] p6spy                                    : #1704178046803 | took 0ms | statement | connection 4| url jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced
select next value for hello_seq
select next value for hello_seq;
2024-01-02T15:47:26.974+09:00 DEBUG 14318 --- [    Test worker] org.hibernate.SQL                        : insert into hello (id) values (?)
2024-01-02T15:47:26.976+09:00  INFO 14318 --- [    Test worker] p6spy                                    : #1704178046976 | took 0ms | statement | connection 4| url jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced
insert into hello (id) values (?)
insert into hello (id) values (1);
2024-01-02T15:47:26.986+09:00 DEBUG 14318 --- [    Test worker] org.hibernate.SQL                        : select h1_0.id from hello h1_0
2024-01-02T15:47:26.987+09:00  INFO 14318 --- [    Test worker] p6spy                                    : #1704178046987 | took 0ms | statement | connection 4| url jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced
select h1_0.id from hello h1_0
select h1_0.id from hello h1_0;
2024-01-02T15:47:27.014+09:00  INFO 14318 --- [    Test worker] p6spy                                    : #1704178047014 | took 0ms | rollback | connection 4| url jdbc:h2:mem:a21f98cc-44fd-4380-bad2-49c71d2c5ced

;
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2024-01-02T15:47:27.025+09:00  INFO 14318 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2024-01-02T15:47:27.026+09:00  INFO 14318 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2024-01-02T15:47:27.027+09:00  INFO 14318 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
> Task :test
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 3s
4 actionable tasks: 3 executed, 1 up-to-date
3:47:27 PM: Execution finished ':test --tests "study.querydsl.QuerydslApplicationTests"'.

 

  • h2 db는 기존의 1.4 xx 대를 사용하다, spring boot3로 올리면서 강의자료 대로 2.2.224로 바꾸었습니다.

  • db 생성은 잘 되었고, tcp로 db접근도 완료 했습니다.

  • 생성이 안되는 이유를 모르겠습니다 ㅠㅠ...

 

  • tcp 접근

스크린샷 2024-01-02 오후 3.50.54.png

 

 

  • QHello 위치

     

    스크린샷 2024-01-02 오후 3.52.07.png

 

  • application.yml

     

스크린샷 2024-01-02 오후 3.54.02.png

 

 

 

답변 2

1

안녕하세요. 김주영님, 공식 서포터즈 OMG입니다.

datasource: 와

url: 이 같은 레벨의 띄어쓰기로 되어 있네요 😀

image아래와 같이 띄어쓰기가 되어 있어야 합니다 ^^

image

감사합니다.

김주영님의 프로필 이미지
김주영
질문자

아..이런실수를.. 진짜감사합니다..

 

0

안녕하세요, 인프런 AI 인턴입니다.

해당 질문과 유사한 상황에서 테이블 생성이 안되는 문제를 해결한 사례를 찾았습니다. 아래 링크를 참고하시면 문제 해결에 도움이 될 것 같습니다.

  • 테이블 생성이 안됩니다

    • application.yml의 설정에서 jpa 설정 부분의 들여쓰기가 잘못되어 있어서 발생한 문제로, 올바르게 들여쓰기를 조정하여 해결하였습니다.
  • h2 테이블 생성이 안됩니다

    • ddl-auto 옵션이 none으로 설정되어 있어서 테이블이 생성되지 않는 문제였으며, 이를 create 등으로 변경하여 해결하였습니다.
  • 테이블이 생성이 되지 않습니다.

    • persistence.xml에 create 부분이 주석 처리되어 있어서 테이블이 생성되지 않았던 문제를 수정하여 해결하였습니다.

링크된 내용을 확인하여 application.yml 파일의 설정을 다시 검토해 보시기 바랍니다. 설정의 들여쓰기, ddl-auto 옵션 등을 확인하여 문제를 해결해 보시길 권장합니다.

김주영님의 프로필 이미지
김주영

작성한 질문수

질문하기