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
반응형