J'ai vraiment besoin d'aide. J'ai cherché dans toutes les questions que j'ai trouvées sur stackoverflow et rien ne fonctionne. Je n'ai jamais utilisé l'hibernation auparavant et je ne sais pas ce que je fais mal.
Voici mon référentiel: https://github.com/ionutincau/test_db
Je reçois cette erreur:
"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
dans votre fichier CFG s'il vous plaît changer le dialecte Hibernate
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
J'ai eu cette erreur en essayant de créer une entité JPA avec le nom "User" (dans Postgres) qui est réservé. La solution consiste donc à changer le nom de la table en annotations @Table:
@Entity
@Table(name="users")
public class User {..}
Ou changez le nom de la table manuellement.
J'ai eu cette même erreur quand j'essayais de faire une table avec le nom "admin". Ensuite, j'ai utilisé l'annotation @Table et donné à la table un nom différent, comme @Table (name = "admins"). Je pense que certains mots sont réservés (comme: - mots-clés en Java) et vous ne pouvez pas les utiliser.
@Entity
@Table(name = "admins")
public class Admin extends TrackedEntity {
}
Je suppose que vous utilisez une ancienne version de Hibernate. Vous pouvez télécharger la dernière version, 5.2, à partir de ici .
La première chose à faire ici est de corriger la version en dialecte de veille prolongée, comme l'a expliqué @JavaLearner. Ensuite, vous devez vous assurer que toutes les versions des dépendances Hibernate que vous utilisez sont à jour. En règle générale, vous avez besoin d'un pilote de base de données tel que mysql-connector-Java
, d'une dépendance hibernate: hibernate-core
et d'un gestionnaire d'entités hibernate: hibernate-entitymanager
. Enfin, n'oubliez pas de vérifier que les tables de la base de données que vous utilisez ne sont pas des mots réservés comme order
, group
, limit
, etc. Cela pourrait vous éviter beaucoup de maux de tête.
Les dialectes sont supprimés dans le SQL récent, utilisez donc
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL57Dialect"/>