Hibernate [Résolu/Fermé]

Signaler
Messages postés
15
Date d'inscription
vendredi 23 janvier 2009
Statut
Membre
Dernière intervention
28 mars 2014
-
dmbi
Messages postés
15
Date d'inscription
vendredi 23 janvier 2009
Statut
Membre
Dernière intervention
28 mars 2014
-
Bonjour,
pour mes début en java, j'ai la tâche de développer une application qui permet d'enregistrer des clients. Pour cela j'ai utilisé hibernate pour les persistances. Je rencontre un problème depuis quelques jour et après quelques modifications l'application plante et je n'arrive pas à revenir au code précédant l'erreur. Pouvez vous m'aider a avancer, le code d'erreur est:

2012-09-20 09:46:17 INFO  [CaseDaoManager,saveOrUpdate,189] SaveOrUpdating  core.dao.Case
2012-09-20 09:46:17 INFO  [HibernateUtil,currentSession,41] Getting current session
2012-09-20 09:46:17 WARN  [JDBCExceptionReporter,logExceptions,77] SQL Error: 1064, SQLState: 42000
2012-09-20 09:46:17 ERROR [JDBCExceptionReporter,logExceptions,78] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Case (creationDate, status, description, affectationDate, comment, kind, Custome' at line 1
org.hibernate.exception.SQLGrammarException: could not insert: [core.dao.Case]
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
	at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
	at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
	at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
	at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
	at core.dao.utils.AbstractDaoManager.saveOrUpdate(AbstractDaoManager.java:192)
	at core.dao.panel.BasePaneCase$2.actionPerformed(BasePaneCase.java:325)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
	at java.awt.Component.processMouseEvent(Component.java:6505)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
	at java.awt.Component.processEvent(Component.java:6270)
	at java.awt.Container.processEvent(Container.java:2229)
	at java.awt.Component.dispatchEventImpl(Component.java:4861)
	at java.awt.Container.dispatchEventImpl(Container.java:2287)
	at java.awt.Component.dispatchEvent(Component.java:4687)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
	at java.awt.Container.dispatchEventImpl(Container.java:2273)
	at java.awt.Window.dispatchEventImpl(Window.java:2719)
	at java.awt.Component.dispatchEvent(Component.java:4687)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
	at java.awt.EventQueue.access$000(EventQueue.java:102)
	at java.awt.EventQueue$3.run(EventQueue.java:662)
	at java.awt.EventQueue$3.run(EventQueue.java:660)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.awt.EventQueue$4.run(EventQueue.java:676)
	at java.awt.EventQueue$4.run(EventQueue.java:674)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Case (creationDate, status, description, affectationDate, comment, kind, Custome' at line 1
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
	at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
	at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
	... 52 more
2012-09-20 09:46:17 ERROR [CaseDaoManager,saveOrUpdate,198] error Save or Updating new core.dao.Case:[ could not insert: [core.dao.Case] ]



2 réponses

Messages postés
79
Date d'inscription
vendredi 7 septembre 2012
Statut
Membre
Dernière intervention
26 mars 2014
5
Bonjour,

2012-09-20 09:46:17 ERROR [JDBCExceptionReporter,logExceptions,78] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Case (creationDate, status, description, affectationDate, comment, kind, Custome' at line 1
org.hibernate.exception.SQLGrammarException: could not insert:


Le problème vient pour moi d'une erreur dans votre requête SQL d'insertion dans la base. Pouvez-vous trouver la ligne correspondante dans votre code et la poster ici ?
Messages postés
15
Date d'inscription
vendredi 23 janvier 2009
Statut
Membre
Dernière intervention
28 mars 2014

La ligne correspondante à mon code d'erreur est :

"casDao.saveOrUpdate(cas); "

qui fait appel a cette fonction:

public synchronized void saveOrUpdate(BaseObject object)
{
Session session = null;
Transaction transaction = null;
if (object == null) {
logger.error("Object is null");

}
try {
logger.info("SaveOrUpdating " + classToManage.getName());
session = HibernateUtil.currentSession();
transaction = session.beginTransaction();
session.saveOrUpdate(object);
transaction.commit();
transaction = session.beginTransaction();
transaction.commit();
} catch (Exception e) {
e.printStackTrace();
logger.error("error Save or Updating new "
+ classToManage.getName() + ":[ "
+ e.getMessage() + " ]");
if (transaction != null) {
transaction.rollback();
}

} finally {
HibernateUtil.closeSession();
}
}
dmbi
Messages postés
15
Date d'inscription
vendredi 23 janvier 2009
Statut
Membre
Dernière intervention
28 mars 2014

le problème venait du fait que j'avais une class Case, qui a le même nom qu'un mot clé de SQL.