TorTukiTu
Messages postés31Date d'inscriptionsamedi 22 avril 2006StatutMembreDernière intervention18 avril 2011
-
18 avril 2011 à 08:51
TorTukiTu
Messages postés31Date d'inscriptionsamedi 22 avril 2006StatutMembreDernière intervention18 avril 2011
-
18 avril 2011 à 09:14
Bonjour,
Je vous écris car j'ai un bug très étrange :
Je cherche simplement à utiliser Hibernate pour ma persistence. J'ai donc besoin d'utiliser un xml de config (hibernate.cfg.xml) pour hibernate.
Mais voilà, le fichier est trouvé avec un simple File() mais l'appel à Configuration.configure("") échoue pour fichier non trouvé. Pourquoi ?
Voici le bout de code qui pose problème :
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
String fileName = "hibernate.cfg.xml";
File f = new File(fileName);
if(!f.exists()){d
System.out.println("Le fichier de configuration "+f.getAbsolutePath()+fileName+" n'existe pas...");
}else{
System.out.println("File "+f.getAbsolutePath()+" found !");
}
return new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
Et voici la sortie :
File C:\Users\Georges\workspace\appli_test\applicationtest\hibernate.cfg.xml found !
18 avr. 2011 10:34:30 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.7
18 avr. 2011 10:34:30 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
18 avr. 2011 10:34:30 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
18 avr. 2011 10:34:30 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
18 avr. 2011 10:34:30 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: hibernate.cfg.xml
18 avr. 2011 10:34:30 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: hibernate.cfg.xml
Initial SessionFactory creation failed.org.hibernate.HibernateException: hibernate.cfg.xml not found
TorTukiTu
Messages postés31Date d'inscriptionsamedi 22 avril 2006StatutMembreDernière intervention18 avril 20111 18 avril 2011 à 09:14
Problème Résolu.
Pour les utilisateurs d'Eclipse, il faut rajouter le ClassPath pointant vers l'endroit où se trouve votre fichier de conf.
Clic droit sur projet -> properties -> Java Build Path ->Libraries -> Add Variable et ajoutez une variable CLASSPATH pointant vers le répertoire où se trouvent vos fichiers de conf Hibernate.