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 :

Problème de lecture du fichier de mapping


Sujet :

Hibernate Java

  1. #1
    Membre confirmé
    Homme Profil pro
    Fondateur
    Inscrit en
    Octobre 2002
    Messages
    445
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Fondateur
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2002
    Messages : 445
    Points : 503
    Points
    503
    Par défaut Problème de lecture du fichier de mapping
    Bonjour,

    Je débute tout juste avec Hibernate. Je suis donc allé sur le site hibernate.org où j'ai téléchagré la version 3.1 de Hibernate. J'ai suivi les instructions de ce tutoriel http://www.hibernate.org/hib_docs/v3.../tutorial.html.

    Je suis donc arrivé jusqu'à la partie 1.2.6 . J'ai donc l'arborescence suivante pour mon projet de test :
    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
     
    +HibernateTest
     .
     +lib
       <Hibernate and third-party libraries>
     +src
       +events
         EventManager.java
         Event.java
         Event.hbm.xml
       +util
         HibernateUtil.java
       hibernate.cfg.xml
       log4j.properties
     +data
     +bin
     build.xml
    Dans mon fichier hibernate.cfg.xml j'ai ça :

    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
     
    <?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>
     
            <!-- Database connection settings -->
            <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
            <property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
            <property name="connection.username">sa</property>
            <property name="connection.password"></property>
     
            <!-- JDBC connection pool (use the built-in) -->
            <property name="connection.pool_size">1</property>
     
            <!-- SQL dialect -->
            <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
     
            <!-- Enable Hibernate's automatic session context management -->
            <property name="current_session_context_class">thread</property>
     
            <!-- Disable the second-level cache  -->
            <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
     
            <!-- Echo all executed SQL to stdout -->
            <property name="show_sql">true</property>
     
            <!-- Drop and re-create the database schema on startup -->
            <property name="hbm2ddl.auto">create</property>
     
            <mapping resource="events/Event.hbm.xml"/>
     
        </session-factory>
     
    </hibernate-configuration>

    et dans mon fichier build.xml j'ai ça :

    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
     
    <project name="hibernate-tutorial" default="compile">
     
        <property name="sourcedir" value="${basedir}/src"/>
        <property name="targetdir" value="${basedir}/bin"/>
        <property name="librarydir" value="${basedir}/lib"/>
     
        <path id="libraries">
            <fileset dir="${librarydir}">
                <include name="*.jar"/>
            </fileset>
        </path>
     
        <target name="clean">
            <delete dir="${targetdir}"/>
            <mkdir dir="${targetdir}"/>
        </target>
     
        <target name="compile" depends="clean, copy-resources">
          <javac srcdir="${sourcedir}"
                 destdir="${targetdir}"
                 classpathref="libraries"/>
        </target>
     
        <target name="copy-resources">
            <copy todir="${targetdir}">
                <fileset dir="${sourcedir}">
                    <exclude name="**/*.java"/>
                </fileset>
            </copy>
        </target>
     
        <target name="run" depends="compile">
        <java fork="true" classname="events.EventManager" classpathref="libraries">
            <classpath path="${targetdir}"/>
            <arg value="${action}"/>
        </java>
    </target>
     
    </project>
    Je lance donc l'utilitaire Ant pour compiler mon projet avec la ligne suivante (comme conseillé dans le tutoriel sur Hibernate) :

    C:\HibernateTest>ant run -Daction=store

    J'obtiens ceci dans la console DOS :

    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
    63
    64
     
    Buildfile: build.xml
     
    clean:
       [delete] Deleting directory C:\HibernateTest\bin
        [mkdir] Created dir: C:\HibernateTest\bin
     
    copy-resources:
         [copy] Copying 3 files to C:\HibernateTest\bin
         [copy] Copied 2 empty directories to 1 empty directory under C:\HibernateTest\bin
     
    compile:
        [javac] Compiling 3 source files to C:\HibernateTest\bin
     
    run:
         [java] 11:28:55,775  INFO Environment:479 - Hibernate 3.1.3
         [java] 11:28:55,785  INFO Environment:509 - hibernate.properties not found
         [java] 11:28:55,795  INFO Environment:525 - using CGLIB reflection optimizer
         [java] 11:28:55,795  INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling
         [java] 11:28:55,895  INFO Configuration:1308 - configuring from resource: /hibernate.cfg.xml
         [java] 11:28:55,895  INFO Configuration:1285 - Configuration resource: /hibernate.cfg.xml
         [java] 11:28:56,065  INFO Configuration:469 - Reading mappings from resource: events/Event.hbm.xml
         [java] 11:28:56,235  INFO HbmBinder:309 - Mapping class: Event -> EVENTS
         [java] Initial SessionFactory creation failed.org.hibernate.MappingException: Could not read mappings from resource: events/Event.hbm.xml
         [java] Exception in thread "main" java.lang.ExceptionInInitializerError
         [java] 	at util.HibernateUtil.<clinit>(Unknown Source)
         [java] 	at events.EventManager.createAndStoreEvent(Unknown Source)
         [java] 	at events.EventManager.main(Unknown Source)
         [java] Caused by: org.hibernate.MappingException: Could not read mappings from resource: events/Event.hbm.xml
         [java] 	at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
         [java] 	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
         [java] 	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
         [java] 	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
         [java] 	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
         [java] 	at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
         [java] 	at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
         [java] 	... 3 more
         [java] Caused by: org.hibernate.MappingException: class Event not found while looking for property: id
         [java] 	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:80)
         [java] 	at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
         [java] 	at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:410)
         [java] 	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:343)
         [java] 	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282)
         [java] 	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
         [java] 	at org.hibernate.cfg.Configuration.add(Configuration.java:386)
         [java] 	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
         [java] 	at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
         [java] 	... 9 more
         [java] Caused by: java.lang.ClassNotFoundException: Event
         [java] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
         [java] 	at java.security.AccessController.doPrivileged(Native Method)
         [java] 	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         [java] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
         [java] 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
         [java] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
         [java] 	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
         [java] 	at java.lang.Class.forName0(Native Method)
         [java] 	at java.lang.Class.forName(Class.java:164)
         [java] 	at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
         [java] 	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:76)
         [java] 	... 17 more
     
    BUILD SUCCESSFUL
    Total time: 3 seconds
    La compilation se passe bien. Le problème vient apparemment du fichier de mapping Event.hbm.xml qu'il n'arrive pas à lire. Pourtant le chemin d'accès est bon je pense.

    Quelqu'un pourrait aurait il une idée plus précise d'où le problème peut venir ?

    Merci d'avance de votre aide.
    Développeur Java / Android.
    The Truth About Bitcoin : https://www.the-truth-about-bitcoin.com/
    In Bitcoin We Trust : https://inbitcoinwetrust.substack.com
    Retrouvez mes Apps Android : https://play.google.com/store/apps/d...01024188312025
    Tout sur le Bitcoin, la Blockchain et les Altcoins : https://www.toutsurlebitcoin.fr
    Devenez une meilleure de vous-même jour après jour : https://www.jedeviensmeilleur.fr

  2. #2
    Membre expérimenté Avatar de maxf1
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 229
    Points : 1 371
    Points
    1 371
    Par défaut
    Montre nous ton fichier Event.hbm.xml
    Une solution a été apporté pour résoudre votre problème alors vous aussi faites en profitez les autres grâce au tag qui se trouve tout en bas de la page....

    Merci de ne pas utiliser les messages privés pour un problème sauf si je vous l'ai explicitement demandé.

    -- Maxf1 --

  3. #3
    Membre confirmé
    Homme Profil pro
    Fondateur
    Inscrit en
    Octobre 2002
    Messages
    445
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Fondateur
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2002
    Messages : 445
    Points : 503
    Points
    503
    Par défaut
    Citation Envoyé par maxf1
    Montre nous ton fichier Event.hbm.xml
    Voila son contenu :

    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"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
     
    <hibernate-mapping>
     
        <class name="Event" table="EVENTS">
            <id name="id" column="EVENT_ID">
                <generator class="increment"/>
            </id>
            <property name="date" type="timestamp" column="EVENT_DATE"/>
            <property name="title"/>
        </class>
     
     
    </hibernate-mapping>
    Développeur Java / Android.
    The Truth About Bitcoin : https://www.the-truth-about-bitcoin.com/
    In Bitcoin We Trust : https://inbitcoinwetrust.substack.com
    Retrouvez mes Apps Android : https://play.google.com/store/apps/d...01024188312025
    Tout sur le Bitcoin, la Blockchain et les Altcoins : https://www.toutsurlebitcoin.fr
    Devenez une meilleure de vous-même jour après jour : https://www.jedeviensmeilleur.fr

  4. #4
    Membre expérimenté Avatar de maxf1
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 229
    Points : 1 371
    Points
    1 371
    Par défaut
    <class name="events.Event" table="EVENTS">
    <id name="id" column="EVENT_ID">
    <generator class="increment"/>
    </id>
    <property name="date" type="timestamp" column="EVENT_DATE"/>
    <property name="title"/>
    </class>
    Une solution a été apporté pour résoudre votre problème alors vous aussi faites en profitez les autres grâce au tag qui se trouve tout en bas de la page....

    Merci de ne pas utiliser les messages privés pour un problème sauf si je vous l'ai explicitement demandé.

    -- Maxf1 --

  5. #5
    Membre confirmé
    Homme Profil pro
    Fondateur
    Inscrit en
    Octobre 2002
    Messages
    445
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Fondateur
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2002
    Messages : 445
    Points : 503
    Points
    503
    Par défaut
    Citation Envoyé par maxf1
    <class name="events.Event" table="EVENTS">
    <id name="id" column="EVENT_ID">
    <generator class="increment"/>
    </id>
    <property name="date" type="timestamp" column="EVENT_DATE"/>
    <property name="title"/>
    </class>

    Merci ça marche.
    J'avais pas pensé qu'il fallait effectivement préfixé la classe avec son chemin depuis le répertoire src/.
    Développeur Java / Android.
    The Truth About Bitcoin : https://www.the-truth-about-bitcoin.com/
    In Bitcoin We Trust : https://inbitcoinwetrust.substack.com
    Retrouvez mes Apps Android : https://play.google.com/store/apps/d...01024188312025
    Tout sur le Bitcoin, la Blockchain et les Altcoins : https://www.toutsurlebitcoin.fr
    Devenez une meilleure de vous-même jour après jour : https://www.jedeviensmeilleur.fr

  6. #6
    Membre expérimenté Avatar de maxf1
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 229
    Points : 1 371
    Points
    1 371
    Par défaut
    De rien. Pense au tag...
    Une solution a été apporté pour résoudre votre problème alors vous aussi faites en profitez les autres grâce au tag qui se trouve tout en bas de la page....

    Merci de ne pas utiliser les messages privés pour un problème sauf si je vous l'ai explicitement demandé.

    -- Maxf1 --

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

Discussions similaires

  1. [POI] Problème de lecture des fichiers Word
    Par Dari dans le forum Documents
    Réponses: 9
    Dernier message: 05/07/2007, 14h08
  2. Problème de lecture sur fichier ini.
    Par braoru dans le forum Delphi
    Réponses: 2
    Dernier message: 28/07/2006, 15h34
  3. [DOM4J] Problème de lecture de fichier xml avec dom4j
    Par santana2006 dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 05/04/2006, 16h52
  4. Problème de lecture de fichier Excel
    Par cocaetjusdorange dans le forum Langage
    Réponses: 4
    Dernier message: 08/02/2006, 11h08
  5. Problème de lecture de fichier Oracle 9.2
    Par fortlow dans le forum Oracle
    Réponses: 4
    Dernier message: 14/11/2005, 16h48

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