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 :

Erreur "javax.persistence.PersistenceException"


Sujet :

Hibernate Java

  1. #1
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2011
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

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

    Informations forums :
    Inscription : Mars 2011
    Messages : 51
    Points : 115
    Points
    115
    Par défaut Erreur "javax.persistence.PersistenceException"
    Bonjour à tous,

    J'ai un problème avec Hibernate, voici le code source de mes entités.
    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
    package rdvmedecins.jpa;
     
    import java.io.Serializable;
    import javax.persistence.Basic;
    import javax.persistence.Column;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.MappedSuperclass;
    import javax.persistence.Version;
     
    /**
     * @author alombardo
     */
    @MappedSuperclass
    public class Personne implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "ID")
        private Long id;
     
        @Basic(optional = false) 
        @Column(name = "TITRE") 
        private String titre; 
     
        @Basic(optional = false) 
        @Column(name = "NOM") 
        private String nom; 
     
        @Basic(optional = false) 
        @Column(name = "VERSION") 
        @Version 
        private int version; 
     
        @Basic(optional = false) 
        @Column(name = "PRENOM") 
        private String prenom;
     
        public Personne() {
        }
     
        public Personne(Long id) {
            this.id = id;
        }
     
        public Personne(Long id, String titre, String nom, int version, String prenom) {
            this.id = id;
            this.titre = titre;
            this.nom = nom;
            this.version = version;
            this.prenom = prenom;
        }
     
        public Long getId() {
            return id;
        }
     
        public void setId(Long id) {
            this.id = id;
        }
     
        public String getTitre() {
            return titre;
        }
     
        public void setTitre(String titre) {
            this.titre = titre;
        }
     
        public String getNom() {
            return nom;
        }
     
        public void setNom(String nom) {
            this.nom = nom;
        }
     
        public int getVersion() {
            return version;
        }
     
        public void setVersion(int version) {
            this.version = version;
        }
     
        public String getPrenom() {
            return prenom;
        }
     
        public void setPrenom(String prenom) {
            this.prenom = prenom;
        }
     
        @Override
        public String toString() {
            return String.format("[%s,%s,%s,%s,%s]", id, version, titre, prenom, nom);
        }
    }
    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
    package rdvmedecins.jpa;
     
    import java.io.Serializable;
    import javax.persistence.Entity;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.Table;
     
    /**
     *
     * @author alombardo
     */
    @Entity
    @Table(name = "clients")
    @NamedQueries({
        @NamedQuery(name = "Client.findAll", query = "SELECT c FROM Client c")
    })
    public class Client extends Personne implements Serializable {
        private static final long serialVersionUID = 1L;
     
        public Client() {
            super();
        }
     
        public Client(Long id) {
            super(id);
        }
     
        public Client(Long id, String titre, String nom, int version, String prenom) {
            super(id, titre, nom, version, prenom);
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            Long id = getId();
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        }
     
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Client)) {
                return false;
            }
            Client other = (Client) object;
            if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.getId().equals(other.getId()))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return String.format("Client %s", super.toString());
        }
    }
    et voici mon message d'erreur
    select c from Client c
    Hibernate:
    select
    client0_.ID as ID3_,
    client0_.NOM as NOM3_,
    client0_.PRENOM as PRENOM3_,
    client0_.TITRE as TITRE3_,
    client0_.VERSION as VERSION3_
    from
    clients client0_
    oct. 28, 2013 2:12:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    WARN: SQL Error: 0, SQLState: 42703
    oct. 28, 2013 2:12:34 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    ERROR: ERREUR: la colonne client0_.id n'existe pas
    Position*: 8
    L'exception suivante s'est produite : javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: ERREUR: la colonne client0_.id n'existe pas
    Position*: 8
    Ma table "clients" sur la BDD PostgresSQL contient les colonnes "ID", "NOM", "VERSION", "PRENOM" et "TITRE".
    Il s'agit du tutoriel de Tahé présent sur DVP.

    Quelqu'un a-t-il une idée du problème ?

    Merci d'avance

  2. #2
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2011
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

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

    Informations forums :
    Inscription : Mars 2011
    Messages : 51
    Points : 115
    Points
    115
    Par défaut
    Bon après avoir fait quelques tests directement sur PGAdmin, j'ai trouvé une piste.
    Hibernate me génère la requête suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    select
        client0_.ID as ID3_,
        client0_.NOM as NOM3_,
        client0_.PRENOM as PRENOM3_,
        client0_.TITRE as TITRE3_,
        client0_.VERSION as VERSION3_ 
    from
        clients client0_
    alors que PGAdmin nécessite cette requête :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    select
        client0_."ID" as ID3_,
        client0_."NOM" as NOM3_,
        client0_."PRENOM" as PRENOM3_,
        client0_."TITRE" as TITRE3_,
        client0_."VERSION" as VERSION3_ 
    from
        clients client0_
    Ci-dessous, voici mon fichier de PersistanceUnit et mon fichier Maven.

    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
     
    <?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="mv-rdvmedecins-jpql-hibernatePU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>rdvmedecins.jpa.Rv</class>
        <class>rdvmedecins.jpa.Medecin</class>
        <class>rdvmedecins.jpa.Creneau</class>
        <class>rdvmedecins.jpa.Client</class>
        <class>rdvmedecins.jpa.Personne</class>
        <properties>
          <property name="hibernate.connection.username" value="admin"/>
          <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
          <property name="hibernate.connection.password" value="admin"/>
          <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/dbrdvmedecins"/>
          <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
          <property name="hibernate.show_sql" value="true"/>
          <property name="hibernate.format_sql" value="true"/>
        </properties>
      </persistence-unit>
    </persistence>
    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
     
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
     
        <groupId>istia.st</groupId>
        <artifactId>mv-rdvmedecins-jpql-hibernate</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
     
        <name>mv-rdvmedecins-jpql-hibernate</name>
        <url>http://maven.apache.org</url>
     
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
     
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>4.1.2</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.logging</groupId>
                <artifactId>jboss-logging</artifactId>
                <version>3.1.0.GA</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.spec.javax.transaction</groupId>
                <artifactId>jboss-transaction-api_1.1_spec</artifactId>
                <version>1.0.0.Final</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>4.1.2</version>
            </dependency>
            <dependency>
                <groupId>antlr</groupId>
                <artifactId>antlr</artifactId>
                <version>2.7.7</version>
            </dependency>
            <dependency>
                <groupId>dom4j</groupId>
                <artifactId>dom4j</artifactId>
                <version>1.6.1</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.0-api</artifactId>
                <version>1.0.1.Final</version>
            </dependency>
            <dependency>
                <groupId>org.javassist</groupId>
                <artifactId>javassist</artifactId>
                <version>3.15.0-GA</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate.common</groupId>
                <artifactId>hibernate-commons-annotations</artifactId>
                <version>4.0.1.Final</version>
            </dependency>
            <dependency>
                <groupId>postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>9.1-901-1.jdbc4</version>
            </dependency>
        </dependencies>
    </project>

  3. #3
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    153
    Détails du profil
    Informations personnelles :
    Sexe : Homme

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

    Informations forums :
    Inscription : Octobre 2009
    Messages : 153
    Points : 105
    Points
    105
    Par défaut
    Slt Rerou, je crois que le code sql généré par hibernate et pas PGAdmin t'induis en erreur. si tu vas directement saisi ta requête dans le client shell de postgres, tu devra le faire sous la même forme généré par hibernate. Le problème que tu as est indiqué dans les log
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ERROR: ERREUR: la colonne client0_.id n'existe pas
    visiblement, ton code semble correct. Je te suggère tout de même de remplacer l'annotation par:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    @Entity
    @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
    public class Personne implements Serializable {
       ...
    }

  4. #4
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2011
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

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

    Informations forums :
    Inscription : Mars 2011
    Messages : 51
    Points : 115
    Points
    115
    Par défaut
    Merci pour ta réponse mysianne mais malheureusement ça ne fonctionne pas mieux :s

Discussions similaires

  1. Réponses: 0
    Dernier message: 21/05/2014, 16h19
  2. Réponses: 10
    Dernier message: 26/07/2012, 14h09
  3. Réponses: 1
    Dernier message: 16/05/2012, 12h55
  4. [Hibernate 3] javax.persistence.PersistenceException
    Par Sensei.f dans le forum Hibernate
    Réponses: 1
    Dernier message: 21/11/2007, 16h52

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