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 :

org.hibernate.InvalidMappingException : Could not parse mapping document from res..


Sujet :

Hibernate Java

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 50
    Points : 37
    Points
    37
    Par défaut org.hibernate.InvalidMappingException : Could not parse mapping document from res..
    Bonjour,

    Je suis en train d'implémenter le tuto Hibernate et je suis confronté à une erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    INFO: Mapping class: Personnes -> personnes
    Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource main/Personnes.hbm.xml
            at org.hibernate.cfg.Configuration.addResource(Configuration.java:539)
            at org.hibernate.cfg.Configuration.addClass(Configuration.java:586)
            at main.main.main(main.java:24)
    Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping Personnes
            at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
            at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:145)
            at org.hibernate.cfg.Configuration.add(Configuration.java:669)
            at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
            at org.hibernate.cfg.Configuration.addResource(Configuration.java:536)
    Voici la config Hibernate :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/scdev</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">eolines</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">true</property>
        <mapping resource="main\Personnes.hbm.xml"/>
      </session-factory>
    </hibernate-configuration>
    Le mapping :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
     <hibernate-mapping>
      <class name="Personnes" table="personnes">
        <id name="idPersonne" type="int" column="idPersonne">
          <generator class="native"/>
        </id>
        <property name="nomPersonne" column="nomPersonne" type="string" not-null="true" />
        <property name="prenomPersonne" column="prenomPersonne" type="string" not-null="true" />
        <property name="datenaissPersonne" column="datenaissPersonne" type="date">
          <meta attribute="field-description">date de naissance</meta>
        </property>
      </class>
    </hibernate-mapping>
    Ma class
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package main;
     
    /**
     *
     * @author mpc
     */
    import java.util.Date;
     
    public class Personnes {
     
      private Integer idPersonne;
      private String nomPersonne;
      private String prenomPersonne;
      private Date datenaissPersonne;
     
      public Personnes(String nomPersonne, String prenomPersonne, Date datenaissPersonne) {
        this.nomPersonne = nomPersonne;
        this.prenomPersonne = prenomPersonne;
        this.datenaissPersonne = datenaissPersonne;
      }
     
      public Personnes() {
      }
     
      public Date getDatenaissPersonne() {
        return datenaissPersonne;
      }
     
      public Integer getIdPersonne() {
        return idPersonne;
      }
     
      public String getNomPersonne() {
        return nomPersonne;
      }
     
      public String getPrenomPersonne() {
        return prenomPersonne;
      }
     
      public void setDatenaissPersonne(Date date) {
        datenaissPersonne = date;
      }
     
      public void setIdPersonne(Integer integer) {
        idPersonne = integer;
      }
     
      public void setNomPersonne(String string) {
        nomPersonne = string;
      }
     
      public void setPrenomPersonne(String string) {
        prenomPersonne = string;
      }
     
    }
    Et mon main :
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package main;
     
    /**
     *
     * @author mpc
     */
     
        /**
         * @param args the command line arguments
         */
    import org.hibernate.*;
    import org.hibernate.cfg.Configuration;
    import java.util.Date;
     
    public class main {
     
      public static void main(String args[]) throws Exception {
        Configuration config = new Configuration().configure("hibernate.cfg.xml");
        config.addClass(Personnes.class);
        SessionFactory sessionFactory = config.buildSessionFactory();
        Session session = sessionFactory.openSession();
     
        Transaction tx = null;
        try {
          tx = session.beginTransaction();
          Personnes personne = new Personnes("nom3", "prenom3", new Date());
          session.save(personne);
          session.flush() ;
          tx.commit();
        } catch (Exception e) {
          if (tx != null) {
            tx.rollback();
          }
          throw e;
        } finally {
          session.close();
        }
     
        sessionFactory.close();
      }
    }
    Je ne vois pas d'où vient l'erreur, tout est syncro entre la DB, ma classe et le mapping

  2. #2
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut
    et avec

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <mapping resource="main/Personnes.hbm.xml"/>

Discussions similaires

  1. Réponses: 8
    Dernier message: 13/08/2014, 17h42
  2. [Erreur]Could not parse mapping document from resource
    Par Le Pharaon dans le forum Hibernate
    Réponses: 5
    Dernier message: 17/06/2009, 10h53
  3. Réponses: 0
    Dernier message: 15/05/2009, 12h13
  4. Réponses: 1
    Dernier message: 12/03/2009, 11h51
  5. erreur: Could not parse mapping document from resource
    Par ferrero dans le forum Hibernate
    Réponses: 1
    Dernier message: 16/05/2007, 19h52

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