Reputation: 677
I am new to hibernate and while working on one example i am getting below error:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.tieto.HibernateUtil.buildSessionFactory(HibernateUtil.java:19)
at com.tieto.HibernateUtil.<clinit>(HibernateUtil.java:8)
at com.tieto.Hib.main(Hib.java:9)
Caused by: 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 org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at com.tieto.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
... 2 more
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)
... 5 more
my hibernate.cfg.xml file is
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">abc</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/abc/Test.hbm.xml" />
</session-factory>
</hibernate-configuration>
Please suggest what i wrong in this??
Upvotes: 3
Views: 16538
Reputation: 31
Copy the dtd from hibernate-mapping-3.0.dtd and hibernate-configuration-3.0.dtd which is inside hibernate folder(path :hibernate3/org/hibernate/hibernate-mapping-3.0.dtd and hibernate3/org/hibernate/hibernate-configuration-3.0.dtd)and paste it in your hbm.xml file and cfg.xml file.
Upvotes: 1
Reputation: 11
you must first, create a file with this name "log4j.properties" (and in a maven project put it in the "resources" folder - subfolder of main folder-) then put this slice of code in pom.xml:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>${basedir}/target</targetPath>
<includes>
<include>log4j.properties</include>
</includes>
</resource>
</resources>
Upvotes: 0
Reputation: 8156
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) ... 5 more
As per the last few lines of the stacktrace, I think the issue is related to the connection of your database.
Please check the name (test)
, username (root)
& password (abc)
of the database, you want to connect to.
Upvotes: 0
Reputation: 5396
Please check all required jar files listed below,
You looks like most concern with log related jars.
Upvotes: 0