-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: hibernate.cfg.xml not found
PostPosted: Fri Apr 09, 2010 5:02 am 
Newbie

Joined: Fri Apr 09, 2010 4:31 am
Posts: 7
Hi to all

I'm a new Hibernate user. I user JBuilder 2006 service pack1 and hibernate 3.
Despite the fact that hibernate.cfg.xml is present, I have this message :
"Initial SessionFactory creation failed.org.hibernate.HibernateException: D:/SERENIX/Projets/JAVA/hibernateTuto/src/hibernate.cfg.xml not found"
To check the existence of hibernate.cfg.xml i've added a code that prints the content of D:/SERENIX/Projets/JAVA/hibernateTuto/src/hibernate.cfg.xml
The content is correctly print as you can see in the output console.

Please I need your urgent help

Thanks



HibernateUtil code
*******************

package com.serenix.hibernate.tuto.tools;



import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.serenix.file.basic.FileManager;


/**
*
* @author KAMGA Marc Olivier
*
*/
public class HibernateUtil {
/**
*
*/
private static final SessionFactory sessionFactory = buildSessionFactory();
/**
*
* @return
*/
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
StringBuffer content = FileManager.getContentBuffer("D:/SERENIX/Projets/JAVA/hibernateTuto/src/hibernate.cfg.xml");
System .out.println("********** Impression contenu de D:/SERENIX/Projets/JAVA/hibernateTuto/src/hibernate.cfg.xml ************");
System .out.println(content.toString());
System .out.println("**********Fin impression contenu de D:/SERENIX/Projets/JAVA/hibernateTuto/src/hibernate.cfg.xml ************");
System .out.println("************************************************************************************************************");
return new Configuration().configure("D:/SERENIX/Projets/JAVA/hibernateTuto/src/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);
}
}
/**
*
* @return
*/
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static final ThreadLocal session = new ThreadLocal();
/**
*
* @return
* @throws HibernateException
*/
public static Session getCurrentSession()
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;
}
/**
*
* @throws HibernateException
*/
public static void closeSession()
throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}

}



Console output
**************

"C:\Program Files\Java\jdk1.6.0_06\bin\javaw" -classpath "D:\SERENIX\Projets\JAVA\hibernateTuto\classes;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\required\hibernate3.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\required\dom4j-1.6.1.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\required\antlr-2.7.6.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\required\slf4j-api-1.5.11.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\required\slf4j-nop-1.5.11.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\required\slf4j-ext-1.5.11.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\required\javassist-3.9.0.GA.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\required\commons-collections-3.1.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\required\jta-1.1.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\bytecode\javassist\javassist-3.9.0.GA.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\bytecode\cglib\cglib-2.2.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\optional\ehcache\ehcache-1.5.0.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\optional\c3p0\c3p0-0.9.1.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\optional\jbosscache\jbosscache-core-3.2.1.GA.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\optional\oscache\oscache-2.1.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\optional\proxool\proxool-0.8.3.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\optional\infinispan\infinispan-core-4.0.0.CR3.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\optional\swarmcache\swarmcache-1.0RC2.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\db\database.jar;D:\SERENIX\Projets\JAVA\hibernateTuto\lib\db\hsqldb.jar;D:\SERENIX\Projets\JAVA\file\classes;D:\SERENIX\tools\poi\poi-3.5-FINAL\poi-3.5-FINAL-20090928.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\poi-ooxml-3.5-FINAL-20090928.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\poi-scratchpad-3.5-FINAL-20090928.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\poi-contrib-3.5-FINAL-20090928.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\ooxml-lib\dom4j-1.6.1.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\ooxml-lib\geronimo-stax-api_1.0_spec-1.0.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\ooxml-lib\ooxml-schemas-1.0.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\ooxml-lib\xmlbeans-2.3.0.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\lib\commons-logging-1.1.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\lib\junit-3.8.1.jar;D:\SERENIX\tools\poi\poi-3.5-FINAL\lib\log4j-1.2.13.jar;D:\SERENIX\Projets\JAVA\reflection\classes;D:\SERENIX\Projets\JAVA\math\classes;C:\Program Files\Java\jdk1.6.0_06\lib\jconsole.jar;C:\Program Files\Java\jdk1.6.0_06\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_06\lib\htmlconverter.jar;C:\Program Files\Java\jdk1.6.0_06\lib\tools.jar;C:\Program Files\Java\jdk1.6.0_06\sample\jnlp\servlet\jardiff.jar;C:\Program Files\Java\jdk1.6.0_06\sample\jnlp\servlet\jnlp.jar;C:\Program Files\Java\jdk1.6.0_06\sample\jnlp\servlet\jnlp-servlet.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\im\indicim.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\im\thaiim.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0_06\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_06\demo\plugin\jfc\Java2D\Java2Demo.jar;C:\Program Files\Java\jdk1.6.0_06\demo\plugin\jfc\CodePointIM\CodePointIM.jar;C:\Program Files\Java\jdk1.6.0_06\demo\jfc\CodePointIM\CodePointIM.jar;C:\Program Files\Java\jdk1.6.0_06\demo\jfc\Java2D\Java2Demo.jar;C:\Program Files\Java\jdk1.6.0_06\demo\scripting\jconsole-plugin\jconsole-plugin.jar" com.serenix.hibernate.tuto.test.Tester
********** Impression contenu de D:/SERENIX/Projets/JAVA/hibernateTuto/src/hibernate.cfg.xml ************
<?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:hsqldb:file:c:\hsqldb\data</property>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.username">SA</property>
<property name="hibernate.connection.password"></property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for HypersonicSQL -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>

<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource="com/serenix/hibernate/tuto/xml/Bank.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Bankbranch.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Company.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Compaccount.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Compcontact.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Euser.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Domain.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Linebusiness.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Businessgrp.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Businesscat.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Coverage.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Linebuscover.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Manager.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Product.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Prodcomp.hbm.xml" />
<mapping resource="com/serenix/hibernate/tuto/xml/Prodversion.hbm.xml" />
</session-factory>
</hibernate-configuration>
**********Fin impression contenu de D:/SERENIX/Projets/JAVA/hibernateTuto/src/hibernate.cfg.xml ************
************************************************************************************************************
Initial SessionFactory creation failed.org.hibernate.HibernateException: D:/SERENIX/Projets/JAVA/hibernateTuto/src/hibernate.cfg.xml not found
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.serenix.hibernate.tuto.tools.HibernateUtil.buildSessionFactory(HibernateUtil.java:42)
at com.serenix.hibernate.tuto.tools.HibernateUtil.<clinit>(HibernateUtil.java:23)
at com.serenix.hibernate.tuto.test.Tester.getBanks(Tester.java:102)
at com.serenix.hibernate.tuto.test.Tester.main(Tester.java:133)
Caused by: org.hibernate.HibernateException: D:/SERENIX/Projets/JAVA/hibernateTuto/src/hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1497)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1519)
at com.serenix.hibernate.tuto.tools.HibernateUtil.buildSessionFactory(HibernateUtil.java:37)
... 3 more


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Fri Apr 09, 2010 5:20 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Actually if the config file is not in the class path, put your config file under WEB-INF folder. you can pass the info to it at initialization time....

Code:
SessionFactory sessions = new Configuration().configure("/WEB-INF/hibernate.cfg.xml").buildSessionFactory();


I've tried this and it works....

I try to keep all my configuration files together, it makes for easier maintenance, documentation and version control (if you keep configuration files in version control).

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Fri Apr 09, 2010 6:41 am 
Newbie

Joined: Fri Apr 09, 2010 4:31 am
Posts: 7
Thanks

I'm doing a web application. Peraphs that's why i don't know where and how put the files in /WEB-INF. Please I need more help about that.

With my JBuilder Project i have this configuration (in french):

Chemin de sortie : D:/SERENIX/Projets/JAVA/hibernateTuto/classes
RĂ©pertoire de travail : D:/SERENIX/Projets/JAVA/hibernateTuto

In the source tab page i have
D:/SERENIX/Projets/JAVA/hibernateTuto/src and D:/SERENIX/Projets/JAVA/hibernateTuto/test


Is there any thing else to do to make D:/SERENIX/Projets/JAVA/hibernateTuto/src include in the classpath?


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Fri Apr 09, 2010 10:23 am 
Newbie

Joined: Fri Apr 09, 2010 4:31 am
Posts: 7
Thanks

I've solve my problems (you can refer to the post in french)


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Mon Apr 26, 2010 2:13 pm 
Newbie

Joined: Mon Apr 26, 2010 2:05 pm
Posts: 1
i also like your problem, you can tell you how to solve it, thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.