wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Could not parse configuration: /hibernate.cfg.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Could not parse configuration: /hibernate.cfg.xml" Watch "Could not parse configuration: /hibernate.cfg.xml" New topic
Author

Could not parse configuration: /hibernate.cfg.xml

nimmi janaki
Greenhorn

Joined: Nov 11, 2011
Posts: 6
Hi,
I am new to hibernate Framework. I am using Eclipse as my IDE. I wrote a small program to save data to postgreSql database. When I run the java application I get the following error. How can I solve this?


SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" 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 org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
at org.nimmi.HibernateTest.main(HibernateTest.java:19)
Caused by: org.dom4j.DocumentException: Error on line 1 of document : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
... 3 more


My hibernate.cfg.xml is

<?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>
- <!-- 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.PostgreSQLDialect</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">create</property>
<mapping resource="org.nimmi.dto.UserDetails" />
</session-factory>
</hibernate-configuration>
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Welcome to CodeRanch, Nimmi Janaki!
From where you got the declaration for the configuration file? Use the one in the documentation of your distribution. It seems the DTD definition is different from the one here (which is for Hibernate 3.3).

And make sure to use code tags when posting java/xml etc... in the forums.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
nimmi janaki
Greenhorn

Joined: Nov 11, 2011
Posts: 6
Vijitha Kumara wrote:Welcome to CodeRanch, Nimmi Janaki!
From where you got the declaration for the configuration file? Use the one in the documentation of your distribution. It seems the DTD definition is different from the one here (which is for Hibernate 3.3).

And make sure to use code tags when posting java/xml etc... in the forums.



Thanks for your reply. I changed to

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

but still the error occurs.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

As the error shows it's something with your xml declaration. I suggest you delete the line completely and type it manually and try again...
nimmi janaki
Greenhorn

Joined: Nov 11, 2011
Posts: 6
Vijitha Kumara wrote:As the error shows it's something with your xml declaration. I suggest you delete the line completely and type it manually and try again...



Issue solved. I had to delete the file, recreate it and type in the code. that seemed to work.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Glad it worked
Dester Raja
Greenhorn

Joined: May 22, 2011
Posts: 17
the best way to resolve the dtd mapping issue is
1. Take the hibernate jar file and unjar/zip them to get the 2 files - hibernate-configuration-3.0.dtd and hibernate-mapping-3.0.dtd
2. Copy the dtd declarations from these two files and use them in your cfg.xml and hbm.xml respectivley.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could not parse configuration: /hibernate.cfg.xml