0

I am stuck with hibernate configuration file exception, this is my hibernate.cfg.xml file:

<?xml version='1.0' encoding='utf-8'?>

<hibernate-configuration
        xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
        xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>
    <property name="connection.username">postgresql</property>
    <property name="connection.password">password</property>

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

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.PostgresPlusDialect</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.internal.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="org.person.PersonModel"/>
  </session-factory>
</hibernate-configuration>

I am using hibernate-core-4.1.12.Final.jar, I am getting the following exception:

INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Exception in thread "main" org.hibernate.MappingException: invalid configuration
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2022)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1939)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1918)
    at org.person.PersonPersistance.main(PersonPersistance.java:14)
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 25; Document is invalid: no grammar found.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

By seeing the respective exception I came to know that I have some mistake in my configuration file. I want to know what mistake I have done in my configuration file.

2
  • Does this answer help: stackoverflow.com/a/12294976/95033 ? Commented Mar 17, 2014 at 11:21
  • thanks for your info, i got the this exception after modifying WARN: HHH000223: Recognized obsolete hibernate namespace hibernate.sourceforge.net. Use namespace hibernate.org/dtd instead. Refer to Hibernate 3.6 Migration Guide! Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml Commented Mar 17, 2014 at 11:55

2 Answers 2

2

When I wrote same program in Eclipse Luno, it has got execute. Try this and see.

Add this before <hibernate-configuration> tag:

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
Sign up to request clarification or add additional context in comments.

1 Comment

Please provide some more information about why you think this solves the problem.
0

With Hibernate 4.x you should use the same DTD as 3.x:

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

 <hibernate-configuration>

 <session-factory>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.