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 :

Hibernate 3.0 : problem parsing configuration/hibernate.cfg.xml


Sujet :

Hibernate Java

  1. #1
    Membre régulier
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mars 2007
    Messages
    162
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 162
    Points : 90
    Points
    90
    Par défaut Hibernate 3.0 : problem parsing configuration/hibernate.cfg.xml
    Bonjour,

    Après quelques mois sur JDBC, je me suis mis à Hibernate 3.0 (enfin, mon patron me l'impose). Je tente depuis la semaine dernière de faire tourner une maquette, je me heurte sans arrêt à l'exception suivante

    J'ai cherché sur le net et sur ce forum d'autres posts à ce sujet, je n'ai pas trouvé la solution. Et pourtant, comme dirait maître Yoda, "certain je suis que la solution sous mes yeux est".

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    Exception in thread "main" org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1173)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
    	at exe.Principale.main(Principale.java:19)
    Caused by: org.dom4j.DocumentException: Error on line 2 of document  : A pseudo attribute name is expected.  Nested exception: A pseudo attribute name is expected. 
    	at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1168)
    	... 3 more
    L'exception indique que je dois mettre l'attribut "name" à la balise <session-factory>, mais pourquoi ?

    Le fichier hibernate.hbm.xml est le suivant :

    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
     
    <?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>
    		<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    		<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/championnat</property>
    		<property name="hibernate.connection.username">root</property>
    		<property name="hibernate.connection.password">justdoit</property>
    		<property name="show_sql">true</property>
    		<!--  Mapping -->
    		<mapping resource="/src/champ/Personne.hbm.xml"/>
    	</session-factory>
    </hibernate-configuration>
    Je ne comprends pas pourquoi je dois mettre un attribut name à la balise <session-factory> alors que je suis en hibernate3... (le fichier MANIFEST.MF indique "Hibernate-Version: 3.0.5")

    Autre précision : je n'utilise pas JNDI. Du moins, pour le moment

    Le fichier Personne.hbm.xml :

    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
     
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
    	"~//Hibernate/Hibernate Mapping DTD 3.0//EN" 
    	"/hibernate-mapping-3.0.dtd">
     
    <hibernate-mapping>
    	<class name="Personne" table="PERSONNE">
    		<id name="OID" column="OID">
    			<generator class="increment"/>
    		</id>
    		<property name="nom"/>
    		<property name="prenom"/>
    		<property name="dateNaissance" type="timestamp" column="DATE_NAISSANCE"/>
    		<property name="licence"/>
    		<property name="arbitre" column="ESTARBITRE"/>
    		<property name="joueur" column="ESTJOUEUR"/>
    		<property name="president" column="ESTPRESIDENT"/>
    	</class>
    </hibernate-mapping>
    Enfin, la classe Principale.java très simplifiée :
    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
     
    package exe;
     
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
     
    public class Principale {
     
    	/**
             * @param args
             */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Configuration configuration;
    		Session session;
    		SessionFactory sessionFactory;
    		//try {
    			configuration = new Configuration();
    			sessionFactory = configuration.configure().buildSessionFactory();
    			session = sessionFactory.openSession();
    		/*} catch (Exception e) {
    			System.out.println(e.toString());
    		}*/
    	}
     
    }
    Si quelqu'un pouvait m'éclairer sur le pourquoi de cette exception, je l'en remercie d'avance. Il est évident que je n'ai pas tout compris d'Hibernate...

  2. #2
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    C'est normal ça ? "utf-8'

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mars 2007
    Messages
    162
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 162
    Points : 90
    Points
    90
    Par défaut
    Citation Envoyé par fr1man Voir le message
    C'est normal ça ? "utf-8'
    Effectivement, ce n'est pas normal.

    Je l'ai supprimé, cela ne change rien.

  4. #4
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    C'était à tout hasard...

    Et si tu remplaçais tes propriétés dialect et show_sql par hibernate.dialect et hibernate.show_sql ?

  5. #5
    Membre régulier
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mars 2007
    Messages
    162
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 162
    Points : 90
    Points
    90
    Par défaut
    Citation Envoyé par fr1man Voir le message
    C'était à tout hasard...

    Et si tu remplaçais tes propriétés dialect et show_sql par hibernate.dialect et hibernate.show_sql ?
    J'ai apporté les modifications suivantes :

    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
     
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-configuration
        PUBLIC "~//Hibernate/Hibernate Configuration DTD//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="connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/championnat</property>
    		<property name="hibernate.connection.username">root</property>
    		<property name="hibernate.connection.password">justdoit</property>
    		<property name="hibernate.show_sql">true</property>
    		<!--  Mapping -->
    		<mapping resource="/src/champ/Personne.hbm.xml"/>
    	</session-factory>
    </hibernate-configuration>
    L'erreur relevée n'est plus la même :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "main" org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1173)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
    	at exe.Principale.main(Principale.java:19)
    Caused by: org.dom4j.DocumentException: Error on line 3 of document  : An invalid XML character (Unicode: 0x7e) was found in the public identifier. Nested exception: An invalid XML character (Unicode: 0x7e) was found in the public identifier.
    	at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1168)
    	... 3 more

  6. #6
    Membre régulier
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mars 2007
    Messages
    162
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 162
    Points : 90
    Points
    90
    Par défaut
    Ah oui !! C'est le tilde ~ au lieu du moins -...

  7. #7
    Membre régulier
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mars 2007
    Messages
    162
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 162
    Points : 90
    Points
    90
    Par défaut
    Les choses progressent soudainement... L'erreur se situe maintenant dans mon fichier Personne.hbm.xml, je vais regarder de plus près !

    Et si tu remplaçais tes propriétés dialect et show_sql par hibernate.dialect et hibernate.show_sql ?
    Merci en tout cas mon cher fr1man Tu avais trouvé pour les valeurs des attributs, super !

    Bon, je regarde mon autre exception...

  8. #8
    Membre régulier
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mars 2007
    Messages
    162
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 162
    Points : 90
    Points
    90
    Par défaut
    C'est parfait, tout fonctionne

  9. #9
    Futur Membre du Club
    Inscrit en
    Novembre 2009
    Messages
    7
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 7
    Points : 7
    Points
    7
    Par défaut
    bonjour je voudrai savoir kel modifiction ont été ajouté au fichier personne.hbm.xml pour ke ça fonctionne car g le mm probleme.merci

  10. #10
    Membre régulier
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mars 2007
    Messages
    162
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 162
    Points : 90
    Points
    90
    Par défaut
    Bonjour,

    Voici les fichiers finaux, en espérant que cela t'aide.

    hibernate.cfg.xml
    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
     
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-configuration
        PUBLIC "-//Hibernate/Hibernate Configuration DTD//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="connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/championnat</property>
    		<property name="hibernate.connection.username">root</property>
    		<property name="hibernate.connection.password">justdoit</property>
    		<property name="hibernate.show_sql">true</property>
    		<!--  Mapping -->
    		<mapping resource="champ/Personne.hbm.xml"/>
    		<mapping resource="champ/Equipe.hbm.xml"/>
    	</session-factory>
    </hibernate-configuration>
    L'erreur provenait dans le chemin du fichier de mapping, j'avais bêtement mis /src/champ/ au lieu de champ/.


    Personne.hbl.xml
    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
     
    <?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="champ.Personne" table="PERSONNE">
    		<id name="OID" column="OID">
    			<generator class="increment"/>
    		</id>
    		<property name="nom"/>
    		<property name="prenom"/>
    		<property name="dateNaissance" type="date" column="DATE_NAISSANCE"/>
    		<property name="licence"/>
    		<property name="arbitre" column="ESTARBITRE"/>
    		<property name="joueur" column="ESTJOUEUR"/>
    		<property name="president" column="ESTPRESIDENT"/>
    		<many-to-one name="equipe" column="OID_EQUIPE"/>
    	</class>
    </hibernate-mapping>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Could not parse configuration : /hibernate.cfg.xml
    Par theflavasavaa dans le forum Hibernate
    Réponses: 10
    Dernier message: 19/03/2015, 11h30
  2. Could not parse configuration: /hibernate.cfg.xml
    Par bpmfouka dans le forum Hibernate
    Réponses: 9
    Dernier message: 21/12/2014, 14h20
  3. problem parsing configuration/hibernate.cfg.xml
    Par gentil dans le forum Hibernate
    Réponses: 3
    Dernier message: 10/01/2008, 23h17
  4. [invalid configuration] probleme dans hibernate.cfg.xml
    Par grelon dans le forum Hibernate
    Réponses: 5
    Dernier message: 21/05/2007, 09h22
  5. problem parsing configuration/hibernate.cfg.xml
    Par allstar dans le forum Hibernate
    Réponses: 2
    Dernier message: 25/08/2006, 07h23

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