webentwicklung-frage-antwort-db.com.de

Ruhezustand Fehler beim Ausführen der DDL über die JDBC-Anweisung

Ich brauche wirklich Hilfe, ich habe in all den Fragen, die ich zu stackoverflow gefunden habe, gesucht und nichts funktioniert. Ich habe den Winterschlaf noch nie benutzt und weiß nicht, was ich falsch mache.
Hier ist mein Repository: https://github.com/ionutincau/test_db

Ich bekomme diesen Fehler:

"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.[email protected]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.[email protected]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.hiber[email protected]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

bitte ändern Sie in Ihrer CFG-Datei den Dialekt für den Ruhezustand

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

Beim Versuch, eine JPA-Entität mit dem reservierten Namen "User" (in Postgres) zu erstellen, ist dieser Fehler aufgetreten. Die Art und Weise, wie dies gelöst wird, besteht darin, den Tabellennamen durch @Table-Annotation zu ändern:

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

Oder ändern Sie den Tabellennamen manuell.

37
Kirill Ch

Ich habe die gleiche Fehlermeldung erhalten, als ich versucht habe, eine Tabelle mit dem Namen "admin" zu erstellen. Dann benutzte ich die @ Table Annotation und gab der Tabelle einen anderen Namen wie @ Table (name = "admins"). Ich denke, einige Wörter sind reserviert (wie: - Schlüsselwörter in Java) und Sie können sie nicht verwenden.

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

}
4
Chaman Gurjar

Ich vermute, Sie verwenden eine alte Version des Ruhezustands. Sie können die neueste Version 5.2 von hier herunterladen.

1
alaa mezain

Als Erstes müssen Sie hier die Version des Dialekts für den Ruhezustand korrigieren, die von @JavaLearner erläutert wurde. Dann müssen Sie sicherstellen, dass alle Versionen der von Ihnen verwendeten Abhängigkeiten im Ruhezustand auf dem neuesten Stand sind. In der Regel benötigen Sie: Datenbanktreiber wie mysql-connector-Java, Abhängigkeit vom Ruhezustand: hibernate-core und Entitätsmanager im Ruhezustand: hibernate-entitymanager. Vergessen Sie nicht zu prüfen, ob die von Ihnen verwendeten Datenbanktabellen nicht die reservierten Wörter wie order, group, limit usw. sind Kopfschmerzen.

1
neaGaze

Dialekte werden in neuem SQL entfernt. Verwenden Sie diese Option

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