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 :

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the r


Sujet :

Hibernate Java

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    802
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 802
    Points : 653
    Points
    653
    Par défaut You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the r
    Je n'arrive pas à insérer mon entity dans ma base MySQL.

    Je pense que cela vient du blob, mais sans en être vraiment certain.

    Voici mon entity :
    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
     
    @Entity
    public class ImageEntity {
     
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	@Id
    	private long id;
     
    	private String key;
     
    	private String title;
     
    	@Column(nullable=false)
    	@Lob
    	private byte[] data;
     
    	@ManyToOne(cascade=CascadeType.ALL, optional=false)
    	private UserEntity proprietaire;
     
    }
    Pour persister mon objet, je fais un simple sessionFactory.save().

    Voici l'erreur que j'obtiens :
    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
     
    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 'key, proprietaire_id, titre) values (_binary'------WebKitFormBoundary8zJ4txsIBmk' 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:526)
    	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:1054)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818)
    	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157)
    	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2460)
    	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2377)
    	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2361)
    	at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    	at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
    	... 110 more
    Voici ma conf hibernate :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
    hibernate.show_sql=true
    hibernate.connection.pool_size=1
    hibernate.hbm2ddl.auto=create
    J'ai aussi essayé avec le dialect org.hibernate.dialect.MySQLDialect, sans davantage de succès :/

  2. #2
    Membre actif
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 152
    Points : 209
    Points
    209
    Par défaut
    Pour te répondre correctement, il manque quelques informations telles que le DDL, l'ensemble des entités en jeu, le code appelant le save() et le SQL généré.

    Mais ce qui saute aux yeux est dans le message d'erreur

    key, proprietaire_id, titre
    Je vois bien key, j'imagine que proprietaire_id est une FK défini dans UserEntity , en revanche tu as un champ title et non titre...

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    802
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 802
    Points : 653
    Points
    653
    Par défaut
    Merci pour ta réponse.

    En fait j'ai trouvé l'origine de mon problème. L'un des attributs de mon entité utilisait un mot clé SQL, en l'occurrence 'key'.
    En espérant que ça aidera quelqu'un d'autre.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 6
    Dernier message: 01/11/2014, 12h55
  2. Réponses: 3
    Dernier message: 27/03/2012, 14h49
  3. [MySQL] erreur dans une boucle ?You have an error in your SQL syntax; check the manual that c
    Par keokaz dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 17/10/2008, 23h08
  4. Erreur incomprehensible:You have an error in your SQL syntax.
    Par Siguillaume dans le forum Requêtes
    Réponses: 2
    Dernier message: 14/06/2008, 10h18
  5. You have an error in your SQL syntax; check the manual ..
    Par Spaccio dans le forum Requêtes
    Réponses: 5
    Dernier message: 09/07/2006, 17h39

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