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

JPA Java Discussion :

Erreur de syntaxe sur ou près de « User »


Sujet :

JPA Java

  1. #1
    Membre éprouvé
    Avatar de michel.di
    Homme Profil pro
    Freelance
    Inscrit en
    Juin 2009
    Messages
    782
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 782
    Points : 1 042
    Points
    1 042
    Par défaut Erreur de syntaxe sur ou près de « User »
    Bonjour à tous,

    Je rencontre actuellement l'erreur suivante :
    erreur de syntaxe sur ou près de « User »

    Pourtant mes 2 entités ne sont pas bien compliquées mais je ne vois pas l'erreur.

    User :
    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
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
     
     
    @Entity
    public class User {
     
    	@Id
    	@GeneratedValue(strategy=GenerationType.AUTO)
    	private Long id;
     
    	private String login;
     
    	private String cryptedPassword;
     
    	private String birthday;
     
    	private String beginDate;
     
    	private boolean isPremium = false;
     
    	@OneToMany(cascade=CascadeType.ALL)
    	private List<Session> sessions;
     
    	public User() {
    		this.sessions = new ArrayList<Session>();
    	}
     
    	public Long getId() {
    		return id;
    	}
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
    	public String getLogin() {
    		return login;
    	}
     
    	public void setLogin(String login) {
    		this.login = login;
    	}
     
    	public String getCryptedPassword() {
    		return cryptedPassword;
    	}
     
    	public void setCryptedPassword(String cryptedPassword) {
    		this.cryptedPassword = cryptedPassword;
    	}
     
    	public String getBirthday() {
    		return birthday;
    	}
     
    	public void setBirthday(String birthday) {
    		this.birthday = birthday;
    	}
     
    	public String getBeginDate() {
    		return beginDate;
    	}
     
    	public void setBeginDate(String beginDate) {
    		this.beginDate = beginDate;
    	}
     
    	public boolean isPremium() {
    		return isPremium;
    	}
     
    	public void setPremium(boolean isPremium) {
    		this.isPremium = isPremium;
    	}
     
    	public List<Session> getSessions() {
    		return sessions;
    	}
     
    	public void setSessions(List<Session> sessions) {
    		this.sessions = sessions;
    	}
     
    	public void addSession(Session session){
    		this.sessions.add(session);
    	}
     
    	public void removeSession(Session session){
    		this.sessions.remove(session);
    	}
    }
    Session :
    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
     
     
    @Entity
    public class Session {
     
    	@Id
    	@GeneratedValue(strategy=GenerationType.AUTO)
    	private Long id;
     
    	private String date;
     
    	public Long getId() {
    		return id;
    	}
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
    	public String getDate() {
    		return date;
    	}
     
    	public void setDate(String date) {
    		this.date = date;
    	}
    }
    Quel est donc le soucis?

    Merci d'avance pour vos réponses
    Docteur en informatique
    Freelance R&D, Web
    Activité freelance : https://redinnov.fr
    Page perso : https://michel-dirix.com/

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par michel.di Voir le message
    Bonjour à tous,

    Je rencontre actuellement l'erreur suivante :
    erreur de syntaxe sur ou près de « User »
    On peux voir l'ouput complet du compilateur ainsi que la classe complète (là on n'a ni les package ni les import)

  3. #3
    Membre éprouvé
    Avatar de michel.di
    Homme Profil pro
    Freelance
    Inscrit en
    Juin 2009
    Messages
    782
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 782
    Points : 1 042
    Points
    1 042
    Par défaut
    Merci pour ta réponse tchize_
    Alors l'erreur complète est :
    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
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
     
    Hibernate: select nextval ('hibernate_sequence')
    Hibernate: insert into User (beginDate, birthday, cryptedPassword, isPremium, login, id) values (?, ?, ?, ?, ?, ?)
    [WARN] /tir_gwt/connection
    javax.persistence.RollbackException: Error while committing the transaction
    	at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:92)
    	at fr.midix.server.DatabaseManager.init(DatabaseManager.java:30)
    	at fr.midix.server.ConnectionServiceImpl.init(ConnectionServiceImpl.java:30)
    	at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    	at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
    	at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:342)
    	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:463)
    	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    	at org.mortbay.jetty.Server.handle(Server.java:324)
    	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
    Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: ERREUR: erreur de syntaxe sur ou près de « User »
      Position*: 13
    	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)
    	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
    	at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:80)
    	... 22 more
    Caused by: org.hibernate.exception.SQLGrammarException: ERREUR: erreur de syntaxe sur ou près de « User »
      Position*: 13
    	at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
    	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
    	at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
    	at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
    	at $Proxy42.executeUpdate(Unknown Source)
    	at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56)
    	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2859)
    	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3300)
    	at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
    	at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
    	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
    	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:275)
    	at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
    	at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
    	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1214)
    	at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:403)
    	at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    	at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
    	at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:75)
    	... 22 more
    Caused by: org.postgresql.util.PSQLException: ERREUR: erreur de syntaxe sur ou près de « User »
      Position*: 13
    	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
    	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
    	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
    	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
    	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
    	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:334)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
    	... 38 more
    User :
    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
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     
    package fr.midix.shared.model;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
     
    @Entity
    public class User {
     
    	@Id
    	@GeneratedValue(strategy=GenerationType.AUTO)
    	private Long id;
     
    	private String login;
     
    	private String cryptedPassword;
     
    	private String birthday;
     
    	private String beginDate;
     
    	private boolean isPremium = false;
     
    	@OneToMany(cascade=CascadeType.ALL)
    	private List<Session> sessions;
     
    	public User() {
    		this.sessions = new ArrayList<Session>();
    	}
     
    	public Long getId() {
    		return id;
    	}
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
    	public String getLogin() {
    		return login;
    	}
     
    	public void setLogin(String login) {
    		this.login = login;
    	}
     
    	public String getCryptedPassword() {
    		return cryptedPassword;
    	}
     
    	public void setCryptedPassword(String cryptedPassword) {
    		this.cryptedPassword = cryptedPassword;
    	}
     
    	public String getBirthday() {
    		return birthday;
    	}
     
    	public void setBirthday(String birthday) {
    		this.birthday = birthday;
    	}
     
    	public String getBeginDate() {
    		return beginDate;
    	}
     
    	public void setBeginDate(String beginDate) {
    		this.beginDate = beginDate;
    	}
     
    	public boolean isPremium() {
    		return isPremium;
    	}
     
    	public void setPremium(boolean isPremium) {
    		this.isPremium = isPremium;
    	}
     
    	public List<Session> getSessions() {
    		return sessions;
    	}
     
    	public void setSessions(List<Session> sessions) {
    		this.sessions = sessions;
    	}
     
    	public void addSession(Session session){
    		this.sessions.add(session);
    	}
     
    	public void removeSession(Session session){
    		this.sessions.remove(session);
    	}
    }
    Session :
    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
    33
     
    package fr.midix.shared.model;
     
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
     
    @Entity
    public class Session {
     
    	@Id
    	@GeneratedValue(strategy=GenerationType.AUTO)
    	private Long id;
     
    	private String date;
     
    	public Long getId() {
    		return id;
    	}
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
    	public String getDate() {
    		return date;
    	}
     
    	public void setDate(String date) {
    		this.date = date;
    	}
    }
    Mon fichier persistence.xml est le suivant :
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
     
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
      <persistence-unit name="tir">
        <properties>
          <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
          <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
          <property name="hibernate.connection.url" value="jdbc:postgresql://127.0.0.1:5432/tir"/>
          <property name="hibernate.show_sql" value="true"/>
          <property name="hibernate.hbm2ddl.auto" value="update"/>
          <property name="hibernate.connection.password" value="midix"/>
          <property name="hibernate.connection.username" value="postgres"/>
          <property name="hibernate.search.default.directory_provider" value="filesystem"/>
        </properties>
      </persistence-unit>
    </persistence>
    Et l'endroit où je crée mon User :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    public static void init(EntityManager entityManager) {
    		entityManager.getTransaction().begin();
    		User user = new User();
    		user.setLogin("midix");
    		user.setCryptedPassword("test");
    		user.setBirthday("14/03/1987");
    		user.setBeginDate("17/12/2012");
     
    		entityManager.persist(user);
    		entityManager.getTransaction().commit();
    	}
    Docteur en informatique
    Freelance R&D, Web
    Activité freelance : https://redinnov.fr
    Page perso : https://michel-dirix.com/

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    User est un mot clé réservé dans postgresql, je ne pense pas que tu puisse l'utiliser comme nom de table. Donne un autre nom à ta table:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    @Entity
    @Table(name="MIDIXUSER")
    public class User {

  5. #5
    Membre éprouvé
    Avatar de michel.di
    Homme Profil pro
    Freelance
    Inscrit en
    Juin 2009
    Messages
    782
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 782
    Points : 1 042
    Points
    1 042
    Par défaut
    Super c'est bien ça! Merci beaucoup!
    Docteur en informatique
    Freelance R&D, Web
    Activité freelance : https://redinnov.fr
    Page perso : https://michel-dirix.com/

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

Discussions similaires

  1. [MySQL] Erreur de syntaxe sur requête
    Par winnie82 dans le forum PHP & Base de données
    Réponses: 12
    Dernier message: 21/03/2006, 13h51
  2. [MySQL] Erreur de syntaxe sur ma requête SELECT
    Par vincedjs dans le forum PHP & Base de données
    Réponses: 14
    Dernier message: 08/03/2006, 11h50
  3. [MySQL] Erreurs de syntaxe sur requêtes DELETE
    Par vincedjs dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 06/03/2006, 15h53
  4. Erreur de syntax sur JOIN
    Par helje dans le forum Requêtes
    Réponses: 2
    Dernier message: 05/03/2006, 17h36
  5. Erreur de syntaxe sur la création d'une vue.
    Par cgougeon dans le forum Installation
    Réponses: 3
    Dernier message: 09/09/2005, 11h00

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