-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Could not read mappings from resource
PostPosted: Mon Oct 24, 2005 5:28 am 
Newbie

Joined: Fri Oct 21, 2005 10:23 am
Posts: 1
Bonjour j'essaie d'uitliser hibernate dans un projet java mais cela n'arrive pas amarcher alors que j'ai le sentiment d'avoir suivi toutes les recommendations ... Quelqu'un peut il m'aider svp ....

Merci

Voici toutes les infos ci dessous


A+ Pierrick

J'utilise Eclipse 3.1 sous windows XP pro sp2

Hibernate version:
hibernate-3.1rc2.zip
Le synchronizer est : HibernateSynchronizer-3.1.1.zip
et la maj des snippets a ete faite avec hibernate3-snippets.zip

Mapping documents:
1) Hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory >

<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:mysql://P2707:3306/JPL</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">pierrick</property>
<property name="hibernate.connection.password">erg</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource="com/pierrick/hibernate/Personne.hbm.xml" />

</session-factory>
</hibernate-configuration>

2) Personne.hbm.xml dans le repertoire com/pierrick/hibernate
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.pierrick.hibernate">
<class name="Personne" table="Personne">

<property name="Id" column="id" type="integer" not-null="true" length="11"/>
<property name="Nom" column="Nom" type="string" not-null="true" length="25" />
<property name="Prenom" column="Prenom" type="string" not-null="true" length="25" />
<property name="Ville" column="Ville" type="string" not-null="true" length="25" />
<property name="Pays" column="Pays" type="string" not-null="true" length="25" />

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Ma classe de test est la suivante :
import java.util.Iterator;
import java.util.List;

import com.pierrick.hibernate.HibernateUtil;
import com.pierrick.hibernate.Personne;

public class Test {

public static void main(String[] args) {
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();

Personne thePersonne = new Personne();

thePersonne.setNom("Moi");
thePersonne.setPrenom("Toi");
thePersonne.setPays("Pays");
thePersonne.setVille("Ville");

HibernateUtil.getSessionFactory().getCurrentSession()
.save(thePersonne);

HibernateUtil.getSessionFactory().getCurrentSession()
.getTransaction().commit();

HibernateUtil.getSessionFactory().getCurrentSession()
.beginTransaction();

List list = HibernateUtil.getSessionFactory().getCurrentSession()
.createQuery("from Personne").list();
Iterator it = list.iterator();
while(it.hasNext())
{
Personne contact = (Personne)it.next();
System.out.println(contact.getNom());
}
HibernateUtil.getSessionFactory().getCurrentSession()
.getTransaction().commit();

HibernateUtil.getSessionFactory().close();
}
}
Full stack trace of any exception that occurs:

Name and version of the database you are using:
MySQL 4.0.18 avec le driver jdbc suivant mysql-connector-java-3.1.11.zip

The generated SQL (show_sql=true):
pas de sql genere car ca ne passe pas le mapping

Message d'erreur envoye par la console
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not read mappings from resource: com/pierrick/hibernate/Personne.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.pierrick.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:17)
at Test.main(Test.java:14)
Caused by: org.hibernate.MappingException: Could not read mappings from resource: com/pierrick/hibernate/Personne.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:476)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1414)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1382)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1363)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1339)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1259)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1245)
at com.pierrick.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 1 more
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:416)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:473)
... 8 more
Caused by: org.xml.sax.SAXParseException: The content of element type "class" 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)*)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:413)
... 9 more


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.