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

조재연님의 프로필 이미지
조재연

작성한 질문수

자바 ORM 표준 JPA 프로그래밍 - 기본편

데이터베이스 스키마 자동 생성

강사님 데이터베이스 스키마 자동생성 실습에서 방언 테스트할때 MySQL로 하면 에러가 발생합니다.

해결된 질문

작성

·

531

2

<!-- 필수 속성 -->
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://localhost/~/test"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>

<!-- 옵션 -->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>
<property name="hibernate.jdbc.batch_size" value="10"/>
<property name="hibernate.hbm2ddl.auto" value="create" />


Hibernate: drop table if exists Member Hibernate: create table Member ( id bigint not null, age integer not null, name varchar(255), primary key (id) ) engine=MyISAM 5월 01, 2021 2:29:55 오전 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@6bda1d19] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode. 5월 01, 2021 2:29:55 오전 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@671facee] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode. 5월 01, 2021 2:29:55 오전 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException WARN: GenerationTarget encountered exception accepting command : Error executing DDL " create table Member ( id bigint not null, age integer not null, name varchar(255), primary key (id) ) engine=MyISAM" via JDBC Statement org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL " create table Member ( id bigint not null, age integer not null, name varchar(255), primary key (id) ) engine=MyISAM" via JDBC Statement at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:56) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) at hellojpa.JpaMain.main(JpaMain.java:10) Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement " CREATE TABLE MEMBER ( ID BIGINT NOT NULL, AGE INTEGER NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID) ) ENGINE=[*]MYISAM"; expected "identifier"; SQL statement: create table Member ( id bigint not null, age integer not null, name varchar(255), primary key (id) ) engine=MyISAM [42001-200]



이런식으로 에러가 발생합니다 ㅜ

답변 1

2

김영한님의 프로필 이미지
김영한
지식공유자

안녕하세요. 재연님

먼저 H2는 mysql와 다릅니다. 따라서 오류가 발생합니다. h2에서 mysql 문법을 일부 지원하는 방법이 있는데, 설정을 다음을 참고해서 고쳐주세요^^

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect

spring.datasource.hikari.jdbc-url=jdbc:h2:mem://localhost/~/test;MODE=MYSQL

감사합니다.

조재연님의 프로필 이미지
조재연
질문자

감사합니다 !

조재연님의 프로필 이미지
조재연

작성한 질문수

질문하기