Hibernate cannot find hibernate.cfg.xml

J

jstorta

I am new to Hibernate. I've installed v3.2.5 and have been going
through the Introduction to Hibernate documentation at hibernate.org.
I am running on Tomcat v6.0.14

Everything is working great except for one thing. I cannot get
Hibernate to find and use the hibernate.cfg.xml file.

If I place the hibernate.cfg.xml file in my WEB-INF/classes directory,
I get the following message in the Tomcat log when I run my test.
21:22:33,298 INFO Environment:547 - hibernate.properties not found

The message did not really concern me since I was not using a
hibernate.properties file. However, my test then fails with the
following exception.
Exception: org.hibernate.HibernateException: Hibernate Dialect must be
explicitly set

The Dialect, and all of the other JDBC parameters are in the
hibernate.cfg.xml so it seems it is just not finding the config file
and is only looking for the hibernate.properties file.


If I create a hibernate.properties file and place it in the same
directory as the hibernate.cfg.xml file, everything works fine.

# ls -al WEB-INF/classes/hibernate*
-rw-rw-r-- 1 webuser webgrp 1463 2008-01-02 21:40 WEB-INF/classes/
hibernate.cfg.xml
-rw-rw-r-- 1 webuser webgrp 14782 2008-01-02 21:40 WEB-INF/classes/
hibernate.properties


The contents of my hibernate.cfg.xml file is listed below in case it
helps.

Any guidance would be appreciated.

Thanks.

### hibernate.cfg.xml #####
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-
configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property
name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/devdb</
property>
<property name="connection.username">dbuser</property>
<property name="connection.password"></property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</
property>

<!-- Enable Hibernate's automatic session context management -- <property name="current_session_context_class">thread</
property>

<!-- Disable the second-level cache -->
<property
name="cache.provider_class">org.hibernate.cache.NoCacheProvider</
property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>

<mapping resource="Project.hbm.xml"/>

</session-factory>

</hibernate-configuration>
 
B

banyvelu

I am new to Hibernate. I've installed v3.2.5 and have been going
through the Introduction to Hibernate documentation at hibernate.org.
I am running on Tomcat v6.0.14

Everything is working great except for one thing. I cannot get
Hibernate to find and use the hibernate.cfg.xml file.

If I place the hibernate.cfg.xml file in my WEB-INF/classes directory,
I get the following message in the Tomcat log when I run my test.
21:22:33,298 INFO Environment:547 - hibernate.properties not found

The message did not really concern me since I was not using a
hibernate.properties file. However, my test then fails with the
following exception.
Exception: org.hibernate.HibernateException: Hibernate Dialect must be
explicitly set

The Dialect, and all of the other JDBC parameters are in the
hibernate.cfg.xml so it seems it is just not finding the config file
and is only looking for the hibernate.properties file.

If I create a hibernate.properties file and place it in the same
directory as the hibernate.cfg.xml file, everything works fine.

# ls -al WEB-INF/classes/hibernate*
-rw-rw-r-- 1 webuser webgrp 1463 2008-01-02 21:40 WEB-INF/classes/
hibernate.cfg.xml
-rw-rw-r-- 1 webuser webgrp 14782 2008-01-02 21:40 WEB-INF/classes/
hibernate.properties

The contents of my hibernate.cfg.xml file is listed below in case it
helps.

Any guidance would be appreciated.

Thanks.

### hibernate.cfg.xml #####
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-
configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property
name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/devdb</
property>
<property name="connection.username">dbuser</property>
<property name="connection.password"></property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</
property>

<!-- Enable Hibernate's automatic session context management --

<property name="current_session_context_class">thread</
property>

<!-- Disable the second-level cache -->
<property
name="cache.provider_class">org.hibernate.cache.NoCacheProvider</
property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>

<mapping resource="Project.hbm.xml"/>

</session-factory>

</hibernate-configuration>

can u just post the actual class implementation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top