• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could not parse configuration: /hibernate.cfg.xml

 
nimmi janaki
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3916
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
nimmi janaki
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3916
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3916
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad it worked
 
Dester Raja
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic