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 :

Eclipse-Hibernate-erreur Execution


Sujet :

Hibernate Java

  1. #1
    Invité
    Invité(e)
    Par défaut Eclipse-Hibernate-erreur Execution
    Salut a vous tous
    je debute le developpement sous eclipse avec Hibernate et j'ai rencontrer un probleme d'execution de mon programme
    voici l'erreur qu'il me donne:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Exception in thread "main" java.lang.ExceptionInInitializerError
    	at Test.main(Test.java:24)
    Caused by: java.lang.ClassCastException: org.hibernate.transaction.JDBCTransactionFactory
    	at net.sf.hibernate.transaction.TransactionFactoryFactory.buildTransactionFactory(TransactionFactoryFactory.java:34)
    	at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:66)
    	at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1155)
    	at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:789)
    	at com.minosis.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
    	... 1 more

    voici le code de mon fichier 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
    <?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://localhost/hibernate</property>
    		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="hibernate.connection.username">root</property>
    		<property name="hibernate.connection.password"></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>
        </session-factory>
    </hibernate-configuration>

    et le code de employer.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
    33
    34
    35
    36
    <?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.minosis.hibernate">
    	<class
    		name="Employer"
    		table="employer"
    	>
     
    		<property
    			name="Id"
    			column="id"
    			type="string"
    			not-null="true"
    			length="5"
    		/>
    		<property
    			name="Nom"
    			column="nom"
    			type="string"
    			not-null="true"
    			length="50"
    		/>
    		<property
    			name="Prenom"
    			column="prenom"
    			type="string"
    			not-null="true"
    			length="50"
    		/>
     
     
    	</class>	
    </hibernate-mapping>
    si vous pouvez bien m'aider car j'ai vraiment besoin de ce programme
    P.S j'ai suivie tous les etapes de presque tous les cours sur le net j'ai rassembler tous les .jar necessaire

  2. #2
    zag
    zag est déconnecté
    Membre éclairé

    Profil pro
    Inscrit en
    Mars 2005
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 58
    Par défaut
    Slt,

    d'après l'exception que tu as, on peut voir que dans la classe com.minosis.hibernate.HibernateUtil, tu utilises net.sf.hibernate.cfg.Configuration.

    Or, lors du passage de hibernate2 à 3 les packages net.sf.hibernate.* ont été renommés en org.hibernate*

    Et dans ta config, tu passes org.hibernate.transaction.JDBCTransactionFactory qui hérite de org.hibernate.transaction.TransactionFactory et non net.sf.hibernate.TransactionFactory d'où le ClassCastException

    En résumé change les import ds ta classe HibernateUtil et à l'avenir si tu bosses avec hibernate3, fais attention à utiliser les org.hibernate et non les net.sf dans tes fichiers de config, mais aussi dans tes classes.

    Voilà

  3. #3
    ego
    ego est déconnecté
    Rédacteur

    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juillet 2004
    Messages
    1 883
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Architecte de système d'information
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 883
    Billets dans le blog
    2
    Par défaut
    ??
    Si tu ne mets pas la propriétés hibernate.transaction.factory_class, que ce passe t-il ?

  4. #4
    Invité
    Invité(e)
    Par défaut
    Merci bien pour cette information
    mais j'ai modifier les package j'ai meme cree un nouveau proget et ce que j'ai remarquer c que l'erreur a changer voila ce qu'il me donne mnt


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Exception in thread "main" org.hibernate.MappingException: Unknown entity: mapping.Employer
    	at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514)
    	at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1302)
    	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:89)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
    	at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
    	at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
    	at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
    	at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
    	at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
    	at Test.main(Test.java:32)

    le code de la classe HibernateUtil.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
     
    package mapping;
     
    import org.hibernate.*;
    import org.hibernate.cfg.*;
     
    public class HibernateUtil {
     
     private static final SessionFactory sessionFactory;
     
     static {
       try {
       // Crée la SessionFactory
       sessionFactory =
    	 new Configuration().configure().buildSessionFactory();
       } catch (HibernateException ex) {
       throw new RuntimeException("Problème de configuration : "
       + ex.getMessage(), ex);
       }
       }
     
     public static final ThreadLocal session = new ThreadLocal();
     
     public static Session currentSession()
    		throws HibernateException {
       Session s = (Session) session.get();
       // Ouvre une nouvelle Session, si ce Thread n'en a aucune
       if (s == null) {
       s = sessionFactory.openSession();
       session.set(s);
       }
       return s;
       }
     
     public static void closeSession()
    		throws HibernateException {
       Session s = (Session) session.get();
       session.set(null);
       if (s != null)
       s.close();
       }
     }

    le code de la classe main Test.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
     
    /*
     * Created on 6 avr. 2006
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
     
    /**
     * @author Administrateur
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
     
    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.Transaction;
     
     
    import mapping.*;
    public class Test {
     
    	public static void main(String[] args)throws HibernateException {
    		Session session = HibernateUtil.currentSession();
     
    		Transaction tx = session.beginTransaction();
     
    		Employer contact = new Employer();
    		contact.setNom("test");
    		contact.setPrenom("test1");
    		contact.setId("001");
    		session.save(contact);
     
    		contact = new Employer();
    		contact.setNom("gst2");
    		contact.setPrenom("ft5");
    		contact.setId("002");
    		session.save(contact);
     
    		tx.commit();
     
    		HibernateUtil.closeSession();
    	}
    }

    merci

  5. #5
    zag
    zag est déconnecté
    Membre éclairé

    Profil pro
    Inscrit en
    Mars 2005
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 58
    Par défaut
    dans employer.hbm.xml tu dit que la classe employer est dans le package com.minosis.hibernate

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <hibernate-mapping package="com.minosis.hibernate">
       <class
          name="Employer"
          table="employer"
       >
    et dans test.java tu dis qu'elle est dans le package mapping :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    import mapping.*;
    c'est pour ca qu'il te dit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Exception in thread "main" org.hibernate.MappingException: Unknown entity: mapping.Employer
    pour hibernate il n'y a donc aucun mapping pour la classe mapping.Employer.

  6. #6
    Invité
    Invité(e)
    Par défaut
    salut
    non s'etais au debut mais quand j'ai refait mon projet quand j'ete informer que hibernate3 a changer de nom pour le package voici mon fichier Employer.hbm

    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"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
     
    <hibernate-mapping package="mapping">
    	<class
    		name="Employer"
    		table="employer"
    	>
     
    		<property
    			name="Id"
    			column="id"
    			type="string"
    			not-null="true"
    			length="5"
    		/>
    		<property
    			name="Nom"
    			column="nom"
    			type="string"
    			not-null="true"
    			length="50"
    		/>
    		<property
    			name="Prenom"
    			column="prenom"
    			type="string"
    			not-null="true"
    			length="50"
    		/>
     
     
    	</class>	
    </hibernate-mapping>
    le code du fichier de configuration

    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
    <?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://localhost/hibernate</property>
    		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="hibernate.connection.username">root</property>
    		<property name="hibernate.connection.password"></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>
        </session-factory>
    </hibernate-configuration>
    Merci

  7. #7
    Invité
    Invité(e)
    Par défaut
    salut svp si qlq un peut me repondre il me donnera une grande aide car j'ai vraiment besoin de l'execution de ce programme
    merci d'avance

  8. #8
    ego
    ego est déconnecté
    Rédacteur

    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juillet 2004
    Messages
    1 883
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Architecte de système d'information
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 883
    Billets dans le blog
    2
    Par défaut
    mais c'est quoi l'erreur maintenant ?
    Si le fichier de config est bien chargé et que le nom de la classe est bon dans le fichier par rapport au nom de la classe Java, quel peut être ton problème ?

  9. #9
    Invité
    Invité(e)
    Par défaut
    salut
    voila l'erreur qu'il me donne tjr
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Exception in thread "main" org.hibernate.MappingException: Unknown entity: mapping.Employer
       at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514)
       at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1302)
       at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:89)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
       at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
       at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
       at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
       at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
       at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
       at Test.main(Test.java:32)
    je sai pa ca vien de koi j'ai tous bien configurer les non des package sont les bon :
    merci encore

  10. #10
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par HrTsDi
    salut
    voila l'erreur qu'il me donne tjr
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Exception in thread "main" org.hibernate.MappingException: Unknown entity: mapping.Employer
       at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514)
       at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1302)
       at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:89)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
       at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
       at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
       at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
       at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
       at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
       at Test.main(Test.java:32)
    je sai pa ca vien de koi : j'ai tous bien configurer les non des package sont les bon les fichier de configuration pareille
    merci encore

  11. #11
    ego
    ego est déconnecté
    Rédacteur

    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juillet 2004
    Messages
    1 883
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Architecte de système d'information
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 883
    Billets dans le blog
    2
    Par défaut
    Je ne vois pas la déclaration de ton fichier hbm dans ton fichier de configuration !?
    Il faut un élément genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <mapping resource="org/hibernate/test/legacy/Simple.hbm.xml"/>

  12. #12
    Invité
    Invité(e)
    Par défaut
    salut
    voila j'ai modifier mon fichier de conf j'ai ajouter cette ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <mapping resource="Employer.hbm.xml"/>
    et voila le fichier de conf
    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
    <?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://localhost/hibernate</property>
    		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="hibernate.connection.username">root</property>
    		<property name="hibernate.connection.password"></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="Employer.hbm.xml"/>
        </session-factory>
    </hibernate-configuration>
    alors l'erreur a changer et il me donne d'autre erreur
    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
    Exception in thread "main" java.lang.ExceptionInInitializerError
    	at Test.main(Test.java:23)
    Caused by: java.lang.RuntimeException: Problème de configuration : Could not read mappings from resource: Employer.hbm.xml
    	at mapping.HibernateUtil.<clinit>(HibernateUtil.java:16)
    	... 1 more
    Caused by: org.hibernate.MappingException: Could not read mappings from resource: Employer.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)
    	at mapping.HibernateUtil.<clinit>(HibernateUtil.java:14)
    	... 1 more
    Caused by: org.hibernate.MappingException: invalid mapping
    	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:425)
    	at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
    	... 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 org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    	at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
    	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    	at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
    	at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
    	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.dom4j.io.SAXReader.read(SAXReader.java:465)
    	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:422)
    	... 9 more
    le fichier de mapping est HibernateUtil son dans les autrse sujet

    je pense avoir besoin d'un example qui marche nickel pour savoir si ca vien de mon ordi car je commence a m'en douter
    merci bien de votre aide

  13. #13
    zag
    zag est déconnecté
    Membre éclairé

    Profil pro
    Inscrit en
    Mars 2005
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 58
    Par défaut
    slt,

    c'est le mapping de ta classe Employer qui n'est pas correct(c'est d'ailleurs ecrit dans ton exception), il ne respecte pas la DTD.
    En fait tu n'a pas déclaré d'identifiant pour Employer, ou plutôt tu ne l'a pas déclaré correctement.
    Il ne faut pas utiliser property mais id pour déclarer ton identifiant dans le mapping.

    Donc remplace :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
        <property
             name="Id"
             column="id"
             type="string"
             not-null="true"
             length="5"
          />
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
            <id name="id" type="string">
                <column name="id" length="5" />
                <generator class="identity" />
            </id>
    pour le générator j'ai mis identity à titre d'exemple, c'est à toi de voir ce qui correspond le mieux à ton appli.

    Sinon, un petit conseil, prend l'habitude de nommer correctement les propriétés de tes beans, il ne faut pas qu'elles commencent par une majuscule. Donc, tu devrais remplacer "Nom" par "nom", "Prenom" par "prenom" et "Id" par "id".

    Voilà, j'espère que ca t'aura aidé

  14. #14
    Invité
    Invité(e)
    Par défaut
    Salut
    oui merci bcp enfin j'ai pu inserer dans la bd et ca marche nickel j'ai aussi pu faire la mise a jour mais le nouveau prob( oui tjr des problemes avec java)
    c'est que la methode find de session se reconnait pa dans mon code il ce souligne en rouge voici le codr
    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
    import mapping.Employer;
    import mapping.HibernateUtil;
    import java.util.*;
    import org.hibernate.Session;
     
    public class Lecture {
     
    	public static void main(String[] args) {
    		Session session = HibernateUtil.currentSession();
    		List list = session.[color=red]find[/color]("from employer where nom='test'");
    		Iterator it = list.iterator();
    		while(it.hasNext())
    		{
    		  Employer contact = (Employer)it.next();
    		  System.out.println(contact.getNom());
    		}
     
    		HibernateUtil.closeSession();
    	}
    }
    merci pour votre aide qui m'a bien aider je l'avoue

  15. #15
    zag
    zag est déconnecté
    Membre éclairé

    Profil pro
    Inscrit en
    Mars 2005
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 58
    Par défaut
    une fois que tu as recupéré une session, tu dois créer ou récupérer une query (HQL, SQL, NamedQuery...) et l'executer.

    Fais donc ca par exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Query query = session.createQuery("from employer where nom=:nom");
    query.setString("nom", test);
    List list = query.list();
    tu peux aussi passer par Criteria (moi j'aime bien je trouve ca bien pratique ):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Criteria criteria = session.createCriteria(Employer.class);
    criteria.add(Restrictions.like("nom","test"));
    List list = criteria.list();
    il ne s'agit là que de quelques exemples, mais le mieux que je puisse te conseiller et de lire la documentation officielle d'hibernate http://www.hibernate.org/hib_docs/v3/reference/fr/html/, tu y trouveras (en général) tout ce dont tu as besoin.

    @+

  16. #16
    Invité
    Invité(e)
    Par défaut
    salut
    merci pour votre code zag mais j'ai pa compris un truc alors voila
    tous dabord test ca sert a koi dans le code :
    encore ta methode de Criteria j'ai pa bien compris
    voila pour le code que j'ai elaborer pour la selection
    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
    public class Lecture {
     
    	public static void main(String[] args)throws HibernateException {
    		Session session = HibernateUtil.currentSession();
    		Query query = session.createQuery("select prenom from employer where nom="+"test");
    		query.setString("nom", "test"); 
    		List list = query.list(); 
    		Iterator it = list.iterator();
     
    		while(it.hasNext())
    		{
    		  Employer contact = (Employer)it.next();
    		  System.out.println(contact.getNom());
    		}
     
    		HibernateUtil.closeSession();
    	}
    }
    voila mais le truc de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    query.setString("nom", "test");
    j'ai pa bien compris
    alors ce code la me genere des erreur et je pense que c normal car j'ai pa compris l'utilisation de query
    merci de votre aide

  17. #17
    Invité
    Invité(e)
    Par défaut
    salut
    personne peut me repondre je suis un peut bloke car je sai pa comment faire une selection la methode find marche pa(je trouve que cette methode dans les cours pourtant eclypse l'indique comme erreur)
    qlq un peut me donner un example de selection ca serai sympa
    merci

  18. #18
    Membre averti
    Inscrit en
    Février 2004
    Messages
    16
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 16
    Par défaut
    'alut,

    pour répondre à ton post du 13/04/2006, il y a déjà un problème dans la définition de ta requête.
    Je pense que ce serait davantage du style :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Query query = session.createQuery("select prenom from employer where nom=:test");
    puis

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    query.setString("test", <valeur de test>);
    test est un paramètre auquel tu donnes une valeur au moment d'exécuter ta quête. Mais bon cela a réellement un intérêt si cette requête est utilisée à plusieurs endroits, dans ce cas tu peux par exemple la stocker dans un fichier de mapping hibernate, parce que sinon autant faire un truc comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Query query = session.createQuery("select prenom from employer where nom=" + "<valeur de nom>");
    Ton erreur vient du fait que tu faisais appel à un paramètre du nom de "nom" qui n'existait pas.

  19. #19
    Membre éprouvé Avatar de et.rond.et.rond
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    110
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 110
    Par défaut
    Citation Envoyé par zag
    slt,

    c'est le mapping de ta classe Employer qui n'est pas correct(c'est d'ailleurs ecrit dans ton exception), il ne respecte pas la DTD.
    En fait tu n'a pas déclaré d'identifiant pour Employer, ou plutôt tu ne l'a pas déclaré correctement.
    Il ne faut pas utiliser property mais id pour déclarer ton identifiant dans le mapping.

    Donc remplace :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
        <property
             name="Id"
             column="id"
             type="string"
             not-null="true"
             length="5"
          />
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
            <id name="id" type="string">
                <column name="id" length="5" />
                <generator class="identity" />
            </id>
    pour le générator j'ai mis identity à titre d'exemple, c'est à toi de voir ce qui correspond le mieux à ton appli.

    Sinon, un petit conseil, prend l'habitude de nommer correctement les propriétés de tes beans, il ne faut pas qu'elles commencent par une majuscule. Donc, tu devrais remplacer "Nom" par "nom", "Prenom" par "prenom" et "Id" par "id".

    Voilà, j'espère que ca t'aura aidé
    génial merci, tu m'as aidé là, ça faisait 2 jours que je bricolais avec Hibernate sans arriver à le faire fonctionner et là grâce à toi j'arrive enfin à lire dans ma table avec Hibernate
    au passage un petit merci aussi à developpez.com et à Google qui m'a fait trouvé cette discution

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 03/03/2010, 20h47
  2. [Install] Eclipse hibernate synchroniser
    Par bonododo dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 08/02/2006, 13h13
  3. [Eclipse][superwaba][erreur]
    Par rmyt dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 17/06/2005, 13h41
  4. [Eclipse / Jonas] Erreur "jonas-entity missing for bean"
    Par citygirl dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 16/05/2005, 11h59
  5. [Ant]Erreur execution d'une tache ANT
    Par gerin dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 11/05/2004, 16h59

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