Hi
below is my hibernate.cfg.xml file. I need help related to cfg.xml file.
I am having problem connecting to database.
Error
started
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
JDBC Driver class not found: oracle.jdbc.driver.OracleDriver
java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:38)
Exception in thread "main"
hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="myeclipse.connection.profile">orcl
</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.username">mis</property>
<property name="connection.password">mis</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Oracle info:
SID : orcl
uid: mis
pwd: mis
[b]below is the example code for sessionfactory[/b]
package roseindia.tutorial.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class FirstExample {
public static void main(String[] args) {
Session session = null;
try{
System.out.println("started");
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
System.out.println("read hibernate.cfg.xml");
session =sessionFactory.openSession();
System.out.println("openSession");
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(3);
contact.setFirstName("Ran");
contact.setLastName("ba");
contact.setEmail("
[email protected]");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();
}
}
}
I need help because this is the first hibernate program i am trying. I am trying but not able to find error.
Please help me