Joined: Wed Oct 14, 2015 8:55 am Posts: 1
|
Hi, I am new to hibernate. I wrote one sample program and getting below error in hibernate.cfg.xml file: Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418) at org.hibernate.cfg.Configuration.configure(Configuration.java:1352) at com.jwt.hibernate.SimpleTest.main(SimpleTest.java:11) Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org at org.dom4j.io.SAXReader.read(SAXReader.java:484) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408) ... 2 more[/b]
Here is my configuration file(hibernate.cfg.xml): <?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">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/hibernatetest</property> <property name="connection.username">root1</property> <property name="connection.password">infy@123</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">create </property> <mapping resource="com/jwt/hibernate/student.hbm.xml" /> </session-factory> </hibernate-configuration>
I have a persistence class as "Student.java". And here is the main class SimpleTest.java: package com.jwt.hibernate; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration;
public class SimpleTest { public static void main(String[] args) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Student student = new Student(); student.setName("Mukesh"); student.setRoll("101"); student.setPhone("8888"); student.setDegree("B.E."); Transaction tx = session.beginTransaction(); session.save(student); System.out.println("Object saved successfully....!!!!"); tx.commit(); session.close(); factory.close(); } }
Kindly suggest.
Thanks Rahul
|
|