Hi,
I am getting the error-
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
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:1542)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at com.javatpoint.mypackage.StoreData.main(StoreData.java:14)
Caused by: org.dom4j.DocumentException: C:\Users\kamlesh\workspace\empdetails\hibernate-configuration-3.0.dtd (The system cannot find the file specified) Nested exception: C:\Users\kamlesh\workspace\empdetails\hibernate-configuration-3.0.dtd (The system cannot find the file specified)
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1532)
... 2 more
hibernate.cfg.xml file-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM "hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hbm2ddl.auto"></property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="connection.username">system</property>
<property name="connection.password">mansi2985</property>
<property name="dialect"> org.Hibernate.dialect.OracleDialect </property>
<mapping resource="employee.hbm.xml" />
</session-factory>
</hibernate-configuration>
StoreData.java-
package com.javatpoint.mypackage;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class StoreData {
public static void main(String[] args){
//creating configuration object
Configuration cfg=new Configuration();
cfg.configure("hibernate.cfg.xml"); //populates the data of the configuration file
//creating session factory object
SessionFactory factory=cfg.buildSessionFactory();
//creating session object
Session session=factory.openSession();
//creating session transaction
Transaction t=session.beginTransaction();
Employee e1=new Employee();
e1.setId(115);
e1.setFirstName("ritesh");
e1.setLastName("kamlesh");
session.persist(e1); //persisting the object
t.commit(); //transaction is committed
session.close();
System.out.println("sussessfully printed");
}
}
hibernate.cfg.xml file-
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration SYSTEM "hibernate-configuration-3.0.dtd" > <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="hbm2ddl.auto"></property> <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property> <property name="connection.username">system</property> <property name="connection.password">-----</property> <property name="dialect"> org.Hibernate.dialect.OracleDialect </property> <mapping resource="employee.hbm.xml" /> </session-factory> </hibernate-configuration>