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 :

Pb Session : entity class not found


Sujet :

Hibernate Java

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 26
    Points : 30
    Points
    30
    Par défaut Pb Session : entity class not found
    Bonjour,
    j'ai bien déclaré toutes les classes dans hibernate.cfg.xml, et pourtant, j'ai cette erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    org.hibernate.MappingException: entity class not found: Utilisateur
    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
    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://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
     
    	<session-factory>
     
    		<!-- Database connection settings -->
    		<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="connection.password"></property>
    		<property name="connection.url">jdbc:mysql://127.0.0.1/tipi_v2</property>
    		<property name="connection.username">root</property>
    		<!-- SQL dialect -->
    		<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
     
    		<!-- Disable the second-level cache -->
    		<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    		<property name="current_session_context_class">thread</property>
     
    		<!-- configuration pool via c3p0--> 
    		<property name="c3p0.acquire_increment">1</property> 
    		<property name="c3p0.idle_test_period">100</property> <!-- seconds --> 
    		<property name="c3p0.max_size">100</property> 
    		<property name="c3p0.max_statements">0</property> 
    		<property name="c3p0.min_size">10</property> 
    		<property name="c3p0.timeout">100</property> <!-- seconds --> 
    		<!-- DEPRECATED very expensive property name="c3p0.validate>-->
     
    		<!-- Echo all executed SQL to stdout -->
    		<property name="show_sql">true</property>
    		<mapping resource="org/hibernate/tutorial/domain/Utilisateur.hbm.xml"/>
    		<mapping resource="org/hibernate/tutorial/domain/Droit.hbm.xml"/>
    		<mapping resource="org/hibernate/tutorial/domain/DroitGroupe.hbm.xml"/>
    		<mapping resource="org/hibernate/tutorial/domain/Profil.hbm.xml"/>
    		<mapping resource="org/hibernate/tutorial/domain/Societe.hbm.xml"/>
    	</session-factory>
     
    </hibernate-configuration>

    Utilisateur.java :

    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    package org.hibernate.tutorial.domain;
    // Generated 29 avr. 2011 14:20:29 by Hibernate Tools 3.4.0.CR1
     
    import java.util.HashSet;
    import java.util.Set;
     
    /**
     * Utilisateur generated by hbm2java
     */
    public class Utilisateur implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
    	private int idUtilisateur;
    	private Societe societe;
    	private Profil profil;
    	private String login;
    	private String password;
    	private Set<?> droits = new HashSet<Object>(0);
     
    	public Utilisateur() {
    	}
     
    	public Utilisateur(int idUtilisateur, Societe societe, Profil profil) {
    		this.idUtilisateur = idUtilisateur;
    		this.societe = societe;
    		this.profil = profil;
    	}
     
    	public Utilisateur(int idUtilisateur, Societe societe, Profil profil, String login, String password, Set<?> droits) {
    		this.idUtilisateur = idUtilisateur;
    		this.societe = societe;
    		this.profil = profil;
    		this.login = login;
    		this.password = password;
    		this.droits = droits;
    	}
     
    	public int getIdUtilisateur() {
    		return this.idUtilisateur;
    	}
     
    	public void setIdUtilisateur(int idUtilisateur) {
    		this.idUtilisateur = idUtilisateur;
    	}
     
    	public Societe getSociete() {
    		return this.societe;
    	}
     
    	public void setSociete(Societe societe) {
    		this.societe = societe;
    	}
     
    	public Profil getProfil() {
    		return this.profil;
    	}
     
    	public void setProfil(Profil profil) {
    		this.profil = profil;
    	}
     
    	public String getLogin() {
    		return this.login;
    	}
     
    	public void setLogin(String login) {
    		this.login = login;
    	}
     
    	public String getPassword() {
    		return this.password;
    	}
     
    	public void setPassword(String password) {
    		this.password = password;
    	}
     
    	public Set<?> getDroits() {
    		return this.droits;
    	}
     
    	public void setDroits(Set<?> droits) {
    		this.droits = droits;
    	}
     
    }
    Utilisateur.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
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Generated 29 avr. 2011 14:20:29 by Hibernate Tools 3.4.0.CR1 -->
    <hibernate-mapping>
        <class name="Utilisateur" table="utilisateur" catalog="tipi_v2">
            <id name="idUtilisateur" type="int">
                <column name="ID_UTILISATEUR" />
                <generator class="assigned" />
            </id>
            <many-to-one name="societe" class="Societe" fetch="select">
                <column name="ID_STE" not-null="true" />
            </many-to-one>
            <many-to-one name="profil" class="Profil" fetch="select">
                <column name="ID_PROFIL" not-null="true" />
            </many-to-one>
            <property name="login" type="string">
                <column name="LOGIN" />
            </property>
            <property name="password" type="string">
                <column name="PASSWORD" />
            </property>
            <set name="droits" table="droit_utilisateur" inverse="true" lazy="true" fetch="select">
                <key>
                    <column name="ID_UTILISATEUR" not-null="true" />
                </key>
                <many-to-many entity-name="Droit">
                    <column name="ID_DROIT" not-null="true" />
                </many-to-many>
            </set>
        </class>
    </hibernate-mapping>
    Merci beaucoup à celui qui pourrais m'aider !

  2. #2
    Membre à l'essai
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2011
    Messages : 11
    Points : 24
    Points
    24
    Par défaut
    Salut,

    Je suis pas un expert de la configuration par fichier hbm (je préfère les annotations ), mais dans la propriété name de la balise class, ne faut -il pas mettre le nom qualifié de ta classe? (dans ton cas org.hibernate.tutorial.domain.Utilisateur)

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 26
    Points : 30
    Points
    30
    Par défaut
    Et est-ce que tu pourrais me dire où je dois placer exactement hibernate.cfg.xml ?
    Tout le monde conseille des chemins différents.
    Des fois c'est org/hibernate/tutorial/domain/Utilisateur, des fois c'est src, des fois war/src.
    J'arrive pas à savoir quel est le bon.

    Autre info pour mon pb:
    Dans Hibernate Configurations, quand j'ouvre une configuration, les classes et la database s'affiche bien, mais la Session Factory dit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <SessionFactory error : entity class not found: Utilisateur>
    A mon avis, le pb est là, en ouvrant simplement une configuration. Je n'ai donc même pas besoin d'exécuter mon logiciel pour voir ce pb.

    Merci !

  4. #4
    Membre à l'essai
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2011
    Messages : 11
    Points : 24
    Points
    24
    Par défaut
    Salut,

    Tu as mal compris ma réponse, en fait dans ton fichier hibernate.cfg.xml tu devrais mettre le nom qualifié de la classe :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <class name="org.hibernate.tutorial.domain.Utilisateur" table="utilisateur" catalog="tipi_v2">
    Sinon pour l'emplacement du fichier hibernate.cfg.xml, le plus important c'est qu'il doit se trouver dans le classpath après suivant l'endroit où tu le mettras, le chemin d'accès sera différent.

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 26
    Points : 30
    Points
    30
    Par défaut
    Qd je fais ce que tu me conseille, et que je fais "build configuration" dans hibernate, ça n'ouvre même plus la config. Ca me dit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    org.hibernate.MappingException: Association references unmapped class: Utilisateur
    Association references unmapped class: Utilisateur
      <No message>
    Si j'essaie de lancer le logiciel, ça me fait la même erreur qu'avant.

    Je pense que :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <class name="Utilisateur" table="utilisateur" catalog="tipi_v2">
    est bon car Utilisateur.hbm.xml et Utilisateur.java sont dans le même dossier.

    Et est-ce que tu aurais une autre idée pour résoudre mon pb ?

Discussions similaires

  1. [Mapping] Erreur "Entity class not found"
    Par yo_haha dans le forum Hibernate
    Réponses: 2
    Dernier message: 17/12/2011, 19h14
  2. [Mapping] Erreur "entity class not found"
    Par SpeedOverflow dans le forum Hibernate
    Réponses: 6
    Dernier message: 20/10/2011, 16h12
  3. Réponses: 4
    Dernier message: 11/06/2010, 13h29
  4. mapping et entity class not found
    Par mauroyb0 dans le forum Hibernate
    Réponses: 8
    Dernier message: 26/03/2007, 14h39
  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