[Error] JPA H2 사용시 MySQL 설정할 때 에러 발생

2024. 9. 6. 08:20·Trouble Shooting(Error)
728x90
반응형

H2로 만든 DB를 MySQL로 설정해서 MySQL의 방언으로 나가는 쿼리를 확인해 보고싶었는데..

에러가 무수히 많이 발생!!

9월 05, 2024 10:35:56 오후 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL "
    alter table MEMBERS 
       drop 
       foreign key FKg1rcvci69xqokrwi7895n05wj" via JDBC [Table "MEMBERS" not found (this database is empty);]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "
    alter table MEMBERS 
       drop 
       foreign key FKg1rcvci69xqokrwi7895n05wj" via JDBC [Table "MEMBERS" not found (this database is empty);]
	at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:94)
	at org.hibernate.tool.schema.internal.Helper.applySqlString(Helper.java:233)
	at org.hibernate.tool.schema.internal.Helper.applySqlStrings(Helper.java:217)
	at org.hibernate.tool.schema.internal.SchemaDropperImpl.applyConstraintDropping(SchemaDropperImpl.java:470)
	at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropConstraintsTablesSequences(SchemaDropperImpl.java:242)
	at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:215)
	at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:185)
	at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:155)
	at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:115)
	at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:244)
	at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.lambda$process$5(SchemaManagementToolCoordinator.java:145)
	at java.base/java.util.HashMap.forEach(HashMap.java:1421)
	at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:142)
	at org.hibernate.boot.internal.SessionFactoryObserverForSchemaExport.sessionFactoryCreated(SessionFactoryObserverForSchemaExport.java:37)
	at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:315)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:450)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1507)
	at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:55)
	at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
	at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
	at hellojpa.Main.main(Main.java:10)
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "MEMBERS" not found (this database is empty); SQL statement:

 

위의 에러도 있고 SEQ 관련된 테이블을 찾을 수 없다는 에러도 나왔음.

에러 자체가 너무 길어서 다 가져오기는 어려웠다.

 

나는 일단 persistence.xml에는 MySQLDialect로 잘 설정을 했고, H2 접속도 잘됐다.

 

알고보니 각 엔티티에 @GeneratedValue 어노테이션을 붙이고 strategy 속성을 안붙여주어 에러가 발생!

MySQL의 AutoIncrement를 사용하기 위해서 기본키 생성 전략을 IDENTITY로 변경했고 정상 동작!!

(PK 생성을 하이버네이트가 아닌 DB에 위임하기 위해서 GenerationType.IDENTITY를 설정해주어야 한다)

728x90
반응형

'Trouble Shooting(Error)' 카테고리의 다른 글

[Error] Spring boot repository null Error / because this.repository in null  (0) 2024.10.15
[Error] Type definition error: [simple type, class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor]  (0) 2024.10.05
[Error] intelliJ, Kotlin - kotlin not configured  (0) 2024.09.04
[Error] 스프링 부트 테스트 extend 관련 에러 발생  (0) 2024.08.21
[Error] Gradle Compile Error, Gradle BUILD FAILED, Gradle Verification Test Error, Task :compileJava FAILED  (0) 2024.07.25
'Trouble Shooting(Error)' 카테고리의 다른 글
  • [Error] Spring boot repository null Error / because this.repository in null
  • [Error] Type definition error: [simple type, class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor]
  • [Error] intelliJ, Kotlin - kotlin not configured
  • [Error] 스프링 부트 테스트 extend 관련 에러 발생
야리니
야리니
오늘보다 내일 더 성장하는 개발자가 되기 위한 야리니 블로그입니다 :)
    반응형
    250x250
  • 야리니
    야리니의 step by step
    야리니
  • 링크

    • GitHub
    • Linkedin
  • 전체
    오늘
    어제
    • 분류 전체보기 (487) N
      • TIL (386) N
        • Java (97)
        • Kotlin (28)
        • JPA (16)
        • Spring (37)
        • Oracle (22)
        • JDBC (7)
        • Web(HTML, CSS, JS, jQuery) (90)
        • View Template (31)
        • AWS (7)
        • HTTP (7)
        • CS (10) N
        • Linux, Unix (2)
        • Python (20)
        • Project (2)
      • Trouble Shooting(Error) (39)
      • Algorithm (15)
      • Git,GitHub (8)
      • Diary (24)
      • 독서 (9)
      • Etc (6)
        • Mac (1)
        • 학원준비과정 (2)
  • 블로그 메뉴

    • 방명록
    • 태그
  • 공지사항

    • 안녕하세요 :)
  • 인기 글

  • 태그

    코틀린
    백엔드 개발자
    java
    국비지원학원
    oracle
    java기초
    HTML
    Kotlin
    CSS
    쌍용교육센터
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.2
야리니
[Error] JPA H2 사용시 MySQL 설정할 때 에러 발생
상단으로

티스토리툴바