This has been driving me crazy since morning.
Now in a maven based project i place my hibernate.cfg.xml file in src/main/resource folder
and i am using following code to set up the connection :
Code:
sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
Now my hibernate.cfg.xml file is :
Code:
<?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>
<property name="hibernate.dialect">
org.hibernate.dialect.Oracle10gDialect
</property>
<property name="hibernate.connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url">
jdbc:oracle:thin:@myIp:1521:mySchema
</property>
<property name="hibernate.connection.username">
myuser
</property>
<property name="hibernate.connection.password">
mypass
</property>
<!-- mapping files -->
<mapping resource="hbm/myFile.hbm.xml" />
</session-factory>
</hibernate-configuration>
I keep on getting the error :
Code:
org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
at com.demo.getSessionFactory(HibernateUtil.java:27)
at com.demo.openSession(HibernateUtil.java:36)
-------------
Caused by: org.dom4j.DocumentException: null Nested exception: null
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
... 179 more
If i move the file to some other folder i get :
Code:
org.hibernate.HibernateException: hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2176)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2157)
at com.demo.getSessionFactory(HibernateUtil.java:27)
at com.demo.openSession(HibernateUtil.java:36)
which means it is in right folder for use.
What am i doing wrong, Is there some jar missing?. I am using dependency
Code:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.7.Final</version>
</dependency>
Maybe there is something really stupid that I am doing but i am unable to figure that out.
TIA