Hibernate

gaouinformaticien Messages postés 25 Date d'inscription samedi 12 juillet 2008 Statut Membre Dernière intervention 10 janvier 2014 - 22 juil. 2010 à 18:21
cs_zedtimi Messages postés 9 Date d'inscription jeudi 19 mars 2009 Statut Membre Dernière intervention 13 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)

<?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>
org.hibernate.dialect.MySQLDialect


com.mysql.jdbc.Driver


jdbc:mysql://Localhost:3306/TPPersonnes


root


kayode


thread


true


<mapping resource="Personne/Personnes.hbm.xml"/>
</session-factory>
</hibernate-configuration>

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)


merci d'avance
gaouinformaticien

1 réponse

cs_zedtimi Messages postés 9 Date d'inscription jeudi 19 mars 2009 Statut Membre Dernière intervention 13 octobre 2010
13 oct. 2010 à 08:53
bonjour,

dit moi svp comment vous avez resoulu ce probleme, j'ai le meme exemple
il faut l'ajout d'un jar!!!

voila ma liste:
dom4j
cglib
hibernate3
log4j
commons.collection
commons.logging
encache
ant.antlr

Merci
0
Rejoignez-nous