gaouinformaticien
Messages postés25Date d'inscriptionsamedi 12 juillet 2008StatutMembreDernière intervention10 janvier 2014
-
22 juil. 2010 à 18:21
cs_zedtimi
Messages postés9Date d'inscriptionjeudi 19 mars 2009StatutMembreDernière intervention13 octobre 2010
-
13 oct. 2010 à 08:53
salut à tous .
je suis debutant en Hibernate.à l'éxecution d'un tp j'ai l'erreur suivante :
[b]Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:508)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:536)/b
j'utilise Netbeans 6.5 et le JDK 1.6 et une BD Mysql
voici mes différents codes
classe Personnes
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;
}
}
fichier de mapping
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Personne.Personnes" table="personnes"/>
<generator class="native"/>
<meta attribute="field-description">date de naissance</meta>
</class>
</hibernate-mapping>
fichier de configuration(se trouve dans un package nommé HibernateConfig)
fichier test
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import java.util.Date;
public class TestHibernate1 {
public static void main(String args[]) throws Exception {
Configuration config = new Configuration();
System.out.println("salut");
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();
}
}
A l' éxecution de la classe TestHibernate1 il y a generation de cette erreur:
GRAVE: Error parsing XML: XML InputStream(4) The content of element type "class" is incomplete, it must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
23 juil. 2010 14:28:36 org.hibernate.util.XMLHelper$ErrorLogger error
GRAVE: Error parsing XML: XML InputStream(13) The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>".
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource Personne/Personnes.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:539)
at org.hibernate.cfg.Configuration.addClass(Configuration.java:586)
at Personne.TestHibernate1.main(TestHibernate1.java:20)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:508)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:536)
... 2 more
Caused by: org.dom4j.DocumentException: Error on line 13 of document : The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>". Nested exception: The element type "hibernate-mapping" must be terminated by the matching end-tag "</hibernate-mapping>".
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)