web-dev-qa-db-ja.com

JDBCステートメントを介してDDLを実行するHibernateエラー

私は本当に私がstackoverflowで見つけたすべての質問で検索した助けが必要で、何も動作しません。私は以前に休止状態を使用したことがなく、何が間違っているのかわかりません。
これが私のリポジトリです: https://github.com/ionutincau/test_db

このエラーが表示されます:

"C:\Program Files\Java\jdk1.8.0_111\bin\Java" "-javaagent:E:\Applications\IntelliJ\IntelliJ IDEA Community Edition 2017.1\lib\idea_rt.jar=50372:E:\Applications\IntelliJ\IntelliJ IDEA Community Edition 2017.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_111\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\rt.jar;C:\Users\ionut\IdeaProjects\test_db\out\production\test_db;C:\Users\ionut\IdeaProjects\test_db\lib\mysql-connector-Java-5.1.41-bin.jar;C:\Users\ionut\IdeaProjects\test_db\lib\hibernate-core-5.2.9.Final.jar;C:\Users\ionut\IdeaProjects\test_db\lib\antlr-2.7.7.jar;C:\Users\ionut\IdeaProjects\test_db\lib\classmate-1.3.0.jar;C:\Users\ionut\IdeaProjects\test_db\lib\dom4j-1.6.1.jar;C:\Users\ionut\IdeaProjects\test_db\lib\hibernate-commons-annotations-5.0.1.Final.jar;C:\Users\ionut\IdeaProjects\test_db\lib\hibernate-jpa-2.1-api-1.0.0.Final.jar;C:\Users\ionut\IdeaProjects\test_db\lib\jandex-2.0.3.Final.jar;C:\Users\ionut\IdeaProjects\test_db\lib\javassist-3.20.0-GA.jar;C:\Users\ionut\IdeaProjects\test_db\lib\jboss-logging-3.3.0.Final.jar;C:\Users\ionut\IdeaProjects\test_db\lib\jboss-transaction-api_1.2_spec-1.0.1.Final.jar;C:\Users\ionut\IdeaProjects\test_db\lib\hibernate-jpamodelgen-5.2.9.Final.jar" Main
Apr 03, 2017 9:05:50 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.9.Final}
Apr 03, 2017 9:05:50 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Apr 03, 2017 9:05:51 PM org.hibernate.annotations.common.reflection.Java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Apr 03, 2017 9:05:51 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Apr 03, 2017 9:05:51 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/test]
Apr 03, 2017 9:05:51 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
Apr 03, 2017 9:05:51 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Apr 03, 2017 9:05:51 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Apr 03, 2017 9:05:51 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Hibernate: drop table if exists User
Apr 03, 2017 9:05:52 PM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@3a12c404] 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.
Hibernate: create table User (userId integer not null, userName varchar(255), primary key (userId)) type=MyISAM
Apr 03, 2017 9:05:52 PM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@59b38691] 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.
Apr 03, 2017 9:05:52 PM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL 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:309)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.Java:445)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.Java:710)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.Java:726)
    at Main.main(Main.Java:19)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'type=MyISAM' at line 1
    at Sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at Sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.Java:62)
    at Sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.Java:45)
    at Java.lang.reflect.Constructor.newInstance(Constructor.Java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.Java:425)
    at com.mysql.jdbc.Util.getInstance(Util.Java:408)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.Java:943)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3973)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3909)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.Java:2527)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.Java:2680)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.Java:2497)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.Java:2455)
    at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.Java:839)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.Java:739)
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.Java:54)
    ... 13 more

Apr 03, 2017 9:05:52 PM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@487db668'
Hibernate: insert into User (userName, userId) values (?, ?)
Apr 03, 2017 9:05:52 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
Apr 03, 2017 9:05:52 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'test.user' doesn't exist
Apr 03, 2017 9:05:52 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
INFO: HHH000010: On release of batch it still contained JDBC statements
Apr 03, 2017 9:05:52 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
ERROR: HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement]
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.Java:147)
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.Java:155)
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.Java:162)
    at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.Java:1434)
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.Java:484)
    at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.Java:3190)
    at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.Java:2404)
    at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.Java:467)
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.Java:146)
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.Java:38)
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.Java:220)
    at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.Java:68)
    at Main.main(Main.Java:23)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.Java:63)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.Java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.Java:111)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.Java:97)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.Java:208)
    at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.Java:45)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.Java:3003)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.Java:3503)
    at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.Java:89)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.Java:586)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.Java:460)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.Java:337)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.Java:39)
    at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.Java:1428)
    ... 9 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.user' doesn't exist
    at Sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at Sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.Java:62)
    at Sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.Java:45)
    at Java.lang.reflect.Constructor.newInstance(Constructor.Java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.Java:425)
    at com.mysql.jdbc.Util.getInstance(Util.Java:408)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.Java:943)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3973)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3909)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.Java:2527)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.Java:2680)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.Java:2501)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.Java:1858)
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.Java:2079)
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.Java:2013)
    at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.Java:5104)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.Java:1998)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.Java:205)
    ... 18 more
26
WhiteShadow

cFGファイルで、休止状態の方言を変更してください

<!-- SQL dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
70
JavaLearner

予約済みの「User」(Postgres内)という名前のJPAエンティティを作成しようとすると、このエラーが発生します。したがって、それを解決する方法は、@ Tableアノテーションによってテーブル名を変更することです。

@Entity
@Table(name="users")
public class User {..}

または、テーブル名を手動で変更します。

37
Kirill Ch

「admin」という名前のテーブルを作成しようとしたときに、同じエラーが発生しました。次に、@ Tableアノテーションを使用して、テーブルに@Table(name = "admins")のような別の名前を付けました。いくつかの単語は予約されていると思います(Javaの:-キーワードなど)。それらは使用できません。

@Entity
@Table(name = "admins")
public class Admin extends TrackedEntity {

}
4
Chaman Gurjar

古いバージョンの休止状態を使用していると思います。 here から最新バージョン5.2をダウンロードできます。

1
alaa mezain

ここで最初に行う必要があるのは、@ JavaLearnerが説明したように、休止状態の方言バージョンを修正することです。次に、使用している休止状態の依存関係のすべてのバージョンが最新であることを確認します。通常、必要なものはmysql-connector-Javaなどのデータベースドライバー、hibernate依存関係:hibernate-core、およびhibernateエンティティマネージャー:hibernate-entitymanagerです。最後に、使用しているデータベーステーブルがordergrouplimitなどの予約語ではないことを確認することを忘れないでください。これにより、頭痛の種が大幅に軽減されます。

1
neaGaze

最近のSQLでは方言が削除されているため、

  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL57Dialect"/>
1
Sai Vankina