Hibernate config - works with .properties not with .cfg.xml

Discussion in 'Java' started by icogs, Nov 20, 2007.

  1. icogs

    icogs Guest

    I have just started working with Hibernate and I am having trouble
    using hibernate.cfg.xml in place of hibernate.properties.

    This rather minimal .properties file works fine:

    hibernate.dialect=org.hibernate.dialect.DerbyDialect
    hibernate.connection.driver_class=org.apache.derby.jdbc.EmbeddedDriver
    hibernate.connection.url=jdbc:derby:MyDB
    hibernate.connection.pool_size=10

    However when I try the following hibernate.cfg.xml instead it doesn't
    appear to pick up any configuration at all:

    <?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="connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</
    property>
    <property name="connection.url">jdbc:derby:MyDB</property>
    <property name="connection.pool_size">10</property>
    <property name="dialect">org.hibernate.dialect.DerbyDialect</
    property>
    </session-factory>
    </hibernate-configuration>

    I am just using core Java in Eclipse and have placed both files at the
    root of my classpath in the bin directory. Attempting to run
    with .cfg.xml gives me the following output:

    20-Nov-2007 17:23:28 org.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 3.2.5
    20-Nov-2007 17:23:28 org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found

    and further down:

    20-Nov-2007 17:23:28
    org.hibernate.connection.UserSuppliedConnectionProvider configure
    WARNING: No connection properties specified - the user must supply
    JDBC connections
    Exception in thread "main" org.hibernate.HibernateException: Hibernate
    Dialect must be explicitly set
    at
    org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:
    57)
    at
    org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:
    39)
    at
    org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:
    426)
    at
    org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:
    128)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:
    2009)
    at
    org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:
    1292)
    at com.icogs.mailist.security.ListLists.main(ListLists.java:17)

    Is my .cfg.xml file wrong or just not being found? I don't know where
    else to put it, it is in the classpath.
    icogs, Nov 20, 2007
    #1
    1. Advertising

  2. icogs

    Arne Vajhøj Guest

    icogs wrote:
    > I have just started working with Hibernate and I am having trouble
    > using hibernate.cfg.xml in place of hibernate.properties.
    >
    > This rather minimal .properties file works fine:
    >
    > hibernate.dialect=org.hibernate.dialect.DerbyDialect
    > hibernate.connection.driver_class=org.apache.derby.jdbc.EmbeddedDriver
    > hibernate.connection.url=jdbc:derby:MyDB
    > hibernate.connection.pool_size=10
    >
    > However when I try the following hibernate.cfg.xml instead it doesn't
    > appear to pick up any configuration at all:


    > 20-Nov-2007 17:23:28 org.hibernate.cfg.Environment <clinit>
    > INFO: Hibernate 3.2.5
    > 20-Nov-2007 17:23:28 org.hibernate.cfg.Environment <clinit>
    > INFO: hibernate.properties not found


    How do you attempt to instantiate your SessionFactory ?

    Arne
    Arne Vajhøj, Nov 25, 2007
    #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:
    853
    Julie
    Mar 5, 2004
  2. Alexandre Guimond

    libraries options not split in setup.cfg

    Alexandre Guimond, Oct 19, 2006, in forum: Python
    Replies:
    0
    Views:
    249
    Alexandre Guimond
    Oct 19, 2006
  3. solid

    XML Schema and CFG

    solid, Jan 2, 2008, in forum: XML
    Replies:
    2
    Views:
    612
    Joseph Kesselman
    Jan 3, 2008
  4. jstorta
    Replies:
    1
    Views:
    11,756
  5. Eleanna Skouta
    Replies:
    2
    Views:
    8,429
    Arne Vajhøj
    Dec 9, 2008
Loading...

Share This Page