Hibernate cannot find hibernate.cfg.xml

Discussion in 'Java' started by jstorta, Jan 3, 2008.

  1. jstorta

    jstorta Guest

    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>
     
    jstorta, Jan 3, 2008
    #1
    1. Advertising

  2. jstorta

    Guest

    On Jan 3, 8:11 am, jstorta <> wrote:
    > 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
     
    , Jan 19, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. salvage

    CFG / INI file

    salvage, Mar 5, 2004, in forum: C++
    Replies:
    1
    Views:
    882
    Julie
    Mar 5, 2004
  2. Mike Meyer

    distutils setup.cfg question.

    Mike Meyer, Nov 19, 2004, in forum: Python
    Replies:
    2
    Views:
    693
    Mike Meyer
    Nov 19, 2004
  3. icogs
    Replies:
    1
    Views:
    8,781
    Arne Vajhøj
    Nov 25, 2007
  4. solid

    XML Schema and CFG

    solid, Jan 2, 2008, in forum: XML
    Replies:
    2
    Views:
    663
    Joseph Kesselman
    Jan 3, 2008
  5. Eleanna Skouta
    Replies:
    2
    Views:
    8,513
    Arne Vajhøj
    Dec 9, 2008
Loading...

Share This Page