IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

un save qui cause org.hibernate.exception.SQLGrammarException:


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Inscrit en
    Mars 2007
    Messages
    45
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 45
    Points : 42
    Points
    42
    Par défaut un save qui cause org.hibernate.exception.SQLGrammarException:
    Bonjour,
    ma classe de persistance a les attributs suivants :

    Integer idConfig;
    String designation;
    Date dateConfig;
    Short int1;
    Short ext1;
    Short int2;
    Short ext2;
    Short int3;
    Short ext3;
    Short int4;
    Short ext4;

    voici ma fonction pour faire la mise à jour
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
    public void changeconfig(Integer idroue,Integer ext1,Integer ext2,Integer ext3,Integer ext4,Integer int1,Integer int2,Integer int3,Integer int4){
    		Session session;
    		session = HibernateSessionFactory.getSession();
    		FConfigRouesDAO dao = new FConfigRouesDAO();
     
    		// 2. Find  by ID
    		FConfigRoues roue = dao.findById(idroue);
     
    	   	// 3. Change  information
    		Short ext=0;
     
    		roue.setExt1(ext);
    		/*roue.setExt2(ext2);
    	    roue.setExt3(ext3);
    	    roue.setExt4(ext4);
    	    roue.setInt1(int1);
    	    roue.setInt2(int2);
    	    roue.setInt3(int3);
    	    roue.setInt4(int4);*/
     
    		// 4. Start the transaction
    		//Transaction tx = dao.getSession().beginTransaction();
    		Transaction tx = session.beginTransaction();
    		// 5. Update the user record with the changes
    		session.save(roue);
     
    		// 6. Commit the transaction (write to database)
    		tx.commit();
     
    		session.close();
    	}
    j'obtiens cette exception

    Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    at company.BL.Factory.main(Factory.java:471)
    Caused by: java.sql.BatchUpdateException: 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 'int1=1, ext1=1, int2=1, ext2=1, int3=1, ext3=1, int4=0, ext4=0 where Id_Config=1' at line 1
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1213)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:912)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
    ... 8 more

  2. #2
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    Si tu veux modifier un objet :
    - soit tu le load et le modifies dans la même transaction sans save ou autre
    - soit tu le charges dans une session, puis tu pourrais faire un update ou un merge dans une autre sessio,

    En tout cas, n'utilise pas save pour un objet qui existe déjà en base.

Discussions similaires

  1. Réponses: 0
    Dernier message: 28/12/2014, 17h03
  2. Réponses: 9
    Dernier message: 18/12/2014, 08h47
  3. Réponses: 6
    Dernier message: 24/09/2011, 13h03
  4. Réponses: 1
    Dernier message: 30/09/2008, 17h13
  5. [Hibernate] exception SQLGrammarException
    Par K-Kaï dans le forum Hibernate
    Réponses: 14
    Dernier message: 09/07/2007, 11h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo