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 :

Message : /hibernate.cfg.xml not found


Sujet :

Hibernate Java

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Mars 2012
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2012
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Message : /hibernate.cfg.xml not found
    J'ai voulu faire un 1er test avec hibernate, j'ai le message erreur suivant :
    Avertissement: /hibernate.cfg.xml not found.
    J'utilise Eclipse Indigo 1 et Hibernate 2, j'ai testé même avec Netbeans 7 pareil et aussi avec Hibernate 3. J'ai testé aussi de préciser le chemin du dossier dans SessionFactory comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SessionFactory sessionFactory = config.configure("hibernate.cfg.xml").buildSessionFactory();
    ou
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SessionFactory sessionFactory = config.configure("file:///H:/hibernate.cfg.xml").buildSessionFactory();
    J'ai mis le fichier hibernate.cfg.xml partout pareil. Si quelqu'un peut m'aider je galère depuis plusieurs jours. Voilà tous le message sur Eclipse.

    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
    mars 02, 2012 2:42:15 AM net.sf.hibernate.cfg.Environment <clinit>
    Infos: Hibernate 2.1.2
    mars 02, 2012 2:42:15 AM net.sf.hibernate.cfg.Environment <clinit>
    Infos: hibernate.properties not found
    mars 02, 2012 2:42:15 AM net.sf.hibernate.cfg.Environment <clinit>
    Infos: using CGLIB reflection optimizer
    mars 02, 2012 2:42:15 AM net.sf.hibernate.cfg.Configuration configure
    Infos: configuring from resource: /hibernate.cfg.xml
    mars 02, 2012 2:42:15 AM net.sf.hibernate.cfg.Configuration getConfigurationInputStream
    Infos: Configuration resource: /hibernate.cfg.xml
    mars 02, 2012 2:42:15 AM net.sf.hibernate.cfg.Configuration getConfigurationInputStream
    Avertissement: /hibernate.cfg.xml not found
    Exception in thread "main" net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found
    	at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:831)
    	at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:855)
    	at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:842)
    	at TestHibernate.main(TestHibernate.java:10)
    > Description du projet
    nom projet java=hibernate-test
    base de donne mysql=donnee
    table=users avec 3 colonne:
    id int(11)
    nom varchar (50)
    prenom varchar (50)
    Le fichier hibernate.cfg.xml et User.hbm.xml se trouve dans le classe-path. Les librairies Hibernate et driver de la bdd se trouve dans le dossier lib. La liste des librairies est dans le fichier .classpath ci-dessous.

    > .classpath
    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" encoding="UTF-8"?>
    <classpath>
    	<classpathentry kind="src" path="classe"/>
    	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    	<classpathentry kind="lib" path="lib/cglib-full-2.0.2.jar"/>
    	<classpathentry kind="lib" path="lib/commons-collections-2.1.1.jar"/>
    	<classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"/>
    	<classpathentry kind="lib" path="lib/dom4j-1.4.jar"/>
    	<classpathentry kind="lib" path="lib/ehcache-0.9.jar"/>
    	<classpathentry kind="lib" path="lib/hibernate2.jar"/>
    	<classpathentry kind="lib" path="lib/jta.jar"/>
    	<classpathentry kind="lib" path="lib/jtds-0.8.1.jar"/>
    	<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.18-bin.jar"/>
    	<classpathentry kind="lib" path="lib/odmg-3.0.jar"/>
    	<classpathentry kind="output" path="bin"/>
    </classpath>
    > 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
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
    <hibernate-configuration>
    <session-factory>
    <property name="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost/donnee</property>
    <property name="hibernate.connection.username">myusername</property>
    <property name="hibernate.connection.password">mypassword</property>
    <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
    <mapping resource="User.hbm.xml"/>
    </session-factory>
    </hibernate-configuration>
    > fichier mapping: User.hbm.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?xml version="1.0"?><!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
    <hibernate-mapping>
    <class name="User" table="users">
    <id name="id" type="int" column="id">
    <generator class="identity"/>
    </id>
    <property name="nom" type="string" not-null="true" />
    <property name="prenom" type="string" not-null="true" />
    </class>
    </hibernate-mapping>
    > classe bean:User.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
    public class User {
    private int id;
    private String nom;
    private String prenom;
    public User(String nomPersonne, String prenomPersonne) {
    this.nom = nomPersonne;
    this.prenom= prenomPersonne;
    }
    public User() {
    }
     
    public int getId() {
    	return id;
    	}
    	public String getNom() {
    	return nom;
    	}
    	public String getPrenom() {
    	return prenom;
    	}
     
    	public void setId(int id) {
    	this.id = id;
    	}
    	public void setNomPersonne(String nomPersonne) {
    	this.nom = nomPersonne;
    	}
    	public void setPrenomPersonne(String prenomPersonne) {
    	this.prenom = prenomPersonne;
    	}
    	}
    > classe principale :TestHibernate.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
    import net.sf.hibernate.*;
    import net.sf.hibernate.cfg.Configuration;
    import java.util.*;
    public class TestHibernate {
     
    	/**
             * @param args
             */
    	public static void main(String[] args)throws Exception {
    		Configuration config = new Configuration();
    		config.addClass(User.class);
    		SessionFactory sessionFactory = config.buildSessionFactory();
    		Session session = sessionFactory.openSession();
    		Transaction tx = null;
    		try {
    		tx = session.beginTransaction();
    		User personne = new User("nom3", "prenom3");
    		session.save(personne);
    		session.flush() ;
    		tx.commit();
    		} catch (Exception e) {
    		if (tx != null) {
    		tx.rollback();
    		}
    		throw e;
    		} finally {
    		session.close();
    		}
    		sessionFactory.close();	
     
    	}
     
    }

  2. #2
    Futur Membre du Club
    Femme Profil pro
    Inscrit en
    Février 2013
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Février 2013
    Messages : 3
    Points : 5
    Points
    5
    Par défaut Hibernate connection avec Oracle
    Salut,
    j'arrive pas à résoudre ce problème ,normalement j'ai bien mis en place mes classes et mes fichs ainsi que les jars TOUJOURS pas d'insersion :/
    mais voila ce que ma console affiche :





    2 mars 2013 16:39:28 org.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 3.2.5
    2 mars 2013 16:39:28 org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    2 mars 2013 16:39:28 org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : cglib
    2 mars 2013 16:39:28 org.hibernate.cfg.Environment <clinit>
    INFO: using JDK 1.4 java.sql.Timestamp handling
    2 mars 2013 16:39:28 org.hibernate.cfg.Configuration configure
    INFO: configuring from resource: hibernate.cfg.xml
    2 mars 2013 16:39:28 org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: hibernate.cfg.xml
    Exception in thread "main" org.hibernate.HibernateException: hibernate.cfg.xml not found
    at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
    at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
    at ProtocoleDAO.ProtocoleDAO.main(ProtocoleDAO.java:18)

  3. #3
    Membre actif
    Homme Profil pro
    Analyste/développeur Java EE
    Inscrit en
    Janvier 2005
    Messages
    376
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Belgique

    Informations professionnelles :
    Activité : Analyste/développeur Java EE

    Informations forums :
    Inscription : Janvier 2005
    Messages : 376
    Points : 271
    Points
    271
    Par défaut
    Bonjour,

    Quelle est la hiérarchie de ton projet (dossiers, packages, jar/war,...) ?

    Peut-être une piste pour toi dans ce topic.

    Cdlt,

  4. #4
    Membre averti
    Homme Profil pro
    Inscrit en
    Mai 2011
    Messages
    790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mai 2011
    Messages : 790
    Points : 443
    Points
    443
    Par défaut
    je pense que tu as mis ton hibernate-cfg.xml dans un endroit qui correspond pas à celui mis dans le code

Discussions similaires

  1. Réponses: 2
    Dernier message: 26/02/2014, 14h35
  2. hibernate.cfg.xml Not Found!
    Par MyPaiN dans le forum Hibernate
    Réponses: 9
    Dernier message: 14/05/2009, 13h03
  3. /hibernate.cfg.xml not found
    Par Shixz dans le forum Hibernate
    Réponses: 1
    Dernier message: 22/07/2008, 10h09
  4. [Hibernate] /hibernate.cfg.xml not found
    Par sabour_mounir dans le forum Hibernate
    Réponses: 1
    Dernier message: 18/05/2006, 12h00
  5. [Hibernate] /hibernate.cfg.xml not found
    Par sabour_mounir dans le forum Struts 1
    Réponses: 1
    Dernier message: 17/05/2006, 14h57

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