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] Conf et classe not found


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    74
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 74
    Points : 52
    Points
    52
    Par défaut [HIBERNATE] Conf et classe not found
    Bonjour,

    Voila je débute avec hibernate et j'ai le soucis suivant :

    j'utilise une doc d'hibernate et j'en suis à mon premier essaie, j'ai fait les fichiers de conf et le mapping et lorsque je lance mon test java me dit qu'il ne trouve pas mon POJO, voici mon exemple :

    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
    package events;
    import java.util.Date;
    public class Event {
     
     private long id;
     
     private String title;
     private Date date;
     
     /**
      * @return Returns the date.
      */
     public Date getDate() {
      return date;
     }
     /**
      * @param date The date to set.
      */
     public void setDate(Date date) {
      this.date = date;
     }
     /**
      * @return Returns the id.
      */
     public long getId() {
      return id;
     }
     /**
      * @param id The id to set.
      */
     public void setId(long id) {
      this.id = id;
     }
     /**
      * @return Returns the title.
      */
     public String getTitle() {
      return title;
     }
     /**
      * @param title The title to set.
      */
     public void setTitle(String title) {
      this.title = title;
     }
     
     
    }
    C'est mon object events que j'utilise et voici le mapping associé :

    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
    
    <?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>
    
    Voici aussi mon fichier de conf hibernate

    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
    
    <?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 shema on startup -->
    <property name="hbm2ddl.auto">create</property>
    <mapping resource="events/Event.hbm.xml"/> 
     
    </session-factory>
    </hibernate-configuration> 
    
    Et quand je lance mon programme pour qu'il ajout un objet event dans ma base, voila l'erreur :


    Initial SessionFactory creation
    failed.org.hibernate.MappingException: Could not read mappings from resource: events/Event.hbm.xml
    Exception in thread "main" java.lang.ExceptionInInitializerError
    at util.HibernateUtil.<clinit>(Unknown Source)
    at events.EventManager.createAndStoreEvent(Unknown Source)
    at events.EventManager.main(Unknown Source)
    Caused by:
    org.hibernate.MappingException: Could not read mappings from resource: events/Event.hbm.xml
    at org.hibernate.cfg.Configuration.addResource(
    Configuration.java:485)
    at org.hibernate.cfg.Configuration.parseMappingElement(
    Configuration.java:1465)
    at org.hibernate.cfg.Configuration.parseSessionFactory(
    Configuration.java:1433)
    at org.hibernate.cfg.Configuration.doConfigure(
    Configuration.java:1414)
    at org.hibernate.cfg.Configuration.doConfigure(
    Configuration.java:1390)
    at org.hibernate.cfg.Configuration.configure(
    Configuration.java:1310)
    at org.hibernate.cfg.Configuration.configure(
    Configuration.java:1296)
    ... 3 more
    Caused by:
    org.hibernate.MappingException: class Event not found while looking for property: id
    at org.hibernate.util.ReflectHelper.reflectedPropertyClass(
    ReflectHelper.java:80)
    at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(
    SimpleValue.java:276)
    at org.hibernate.cfg.HbmBinder.bindSimpleId(
    HbmBinder.java:410)
    at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(
    HbmBinder.java:343)
    at org.hibernate.cfg.HbmBinder.bindRootClass(
    HbmBinder.java:282)
    at org.hibernate.cfg.HbmBinder.bindRoot(
    HbmBinder.java:153)
    at org.hibernate.cfg.Configuration.add(
    Configuration.java:386)
    at org.hibernate.cfg.Configuration.addInputStream(
    Configuration.java:427)
    at org.hibernate.cfg.Configuration.addResource(
    Configuration.java:482)
    ... 9 more
    Caused by:
    java.lang.ClassNotFoundException: Event
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(
    Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(
    Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.hibernate.util.ReflectHelper.classForName(
    ReflectHelper.java:108)
    at org.hibernate.util.ReflectHelper.reflectedPropertyClass(
    ReflectHelper.java:76)
    ... 17 more
    Apparement il ne trouve pas mon fichier Events, hors mes fichiers se trouve comme ceci :

    +events
    Event
    event.hbm.xml
    hibernate.cfg.xml

    si vous avez ue idée du pourquoi cet erreur ??

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 274
    Points : 307
    Points
    307
    Par défaut
    Bonjour,

    je dirais qu'il trouve bien ton fichier de mapping mais que le soucis provient du mapping de ta classe event (il faut le nom complet de ta classe, y compris le package)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <hibernate-mapping>
    deviens
    <hibernate-mapping package="events">

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    74
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 74
    Points : 52
    Points
    52
    Par défaut
    Arg merci !!! En effet c'etait évident lol !!!!

    Ca marche nickel ...

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 11/06/2010, 13h29
  2. Réponses: 6
    Dernier message: 06/10/2009, 11h30
  3. Réponses: 5
    Dernier message: 08/05/2009, 18h03
  4. Connexion IRport et Hibernate (component class not found)
    Par imad.elghazoini dans le forum iReport
    Réponses: 4
    Dernier message: 29/06/2007, 11h51
  5. [EJB Session] class not found exception ?
    Par champion dans le forum Wildfly/JBoss
    Réponses: 4
    Dernier message: 11/02/2005, 23h46

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