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