1

getting the below exception in hibernate

log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
    at com.javatpoint.mypackage.StoreData.main(StoreData.java:13)
Caused by: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
    ... 2 more

Hibernate config

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <property name="hbm2ddl.auto">create</property> 
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/platinum</property>
    <property name="hibernate.connection.username">admin</property>
    <property name="hibernate.connection.password">admin</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 

    <mapping resource="employee.hbm.xml" />
</session-factory>
</hibernate-configuration>

Any suggestion?

5
  • check the hibernate version that you are using and the DTD/XSD that is required in the hibernate.cfg.xml for that specific version.That is the first line in your cfg file. That should be matched exactly or the xml parser won't be able to identify and parse you xml and throws the error that you are getting Commented Nov 3, 2014 at 11:51
  • @vikeng21 Thanks for ur suggestion. am new to hibernate could you please help me out by giving detailed explanation. Commented Nov 3, 2014 at 11:53
  • check this link. It wil give you a fair idea. stackoverflow.com/questions/25424118/… and google is your best bet for more info Commented Nov 3, 2014 at 12:01
  • @vikeng21 i have been searching google for the past two days and i have tried possible solutions out there including the link u have provided but still the same. any other suggestion would be great. Commented Nov 4, 2014 at 4:42
  • to be frank i cannot do much sitting here remotely. i still say use google and if you are not familiar with hibernate you can learn and then attempt an example. that is a very commeon error necomers face. we here can only guide you in a direction but you will have to take it further from there. good luck :) Commented Nov 4, 2014 at 5:25

2 Answers 2

1

This one is a temporary solution. Your Hibernate jars contains dtd for validating your configuration xml. Extract ‘hibernate-configuration-3.0.dtd’ and put it in some directory in your project structure (in this case, I have put it in Project root directory). Add your dtd location to DOCTYPE declaration.

<!DOCTYPE hibernate-configuration SYSTEM
"hibernate-configuration-3.0.dtd">

It worked for me. It works when system is offline. Fetches DTD from your local system.

Its just that we have to figure a way to fetch dtd from your jar.

you may do it this way :

<!DOCTYPE hibernate-configuration SYSTEM 
    "classpath://org/hibernate/hibernate-configuration-3.0.dtd">

but then, it is throwing

Caused by: org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath

I was getting a Connection Timed Out error. Yours is a Connection Refused Error. Try this in case 'hibernate.org' is refusing connection.

Sign up to request clarification or add additional context in comments.

Comments

0

In Eclipse Java Project,add hibernate jar file using build path. Add the given following DOCTYPE in the hibernate.cfg.xml(configuration file) Also in the mapping file(save as example.hbm.xml-map class with table in the database) following DOCTYPE

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.