I am trying to connect to mysql database using hibernate from the cfg file as
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//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">
root</property>
<property name="hibernate.connection.pool_size">
10</property>
<property name="show_sql">true</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">
update</property>
<!-- Mapping files -->
<mapping resource="Employee.hbm.xml" />
</session-factory>
</hibernate-configuration>
private static SessionFactory factory;
public static void main(String[] args) {
try {
factory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
ex.fillInStackTrace();
ex.printStackTrace();
throw new ExceptionInInitializerError(ex);
}
Though my connection-string,username,password are correct and the same are working fine in other project with basic jdbc connection, But when I try it using hibernate I am getting this error on console
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.hibernate.ManageEmployee.main(ManageEmployee.java:21)
Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at com.hibernate.ManageEmployee.main(ManageEmployee.java:19)
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)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at com.hibernate.ManageEmployee.main(ManageEmployee.java:16)
And yes the database server is up and running but the connections from this hibernate application are refused