Hi all,
I am new in Hibernate. I am getting sessionfactory object as null. But the configuration in hibernate.cfg.xml file seems to be ok.
Code:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@10.1.1.1:1521:test</property>
<property name="hibernate.connection.username">ORV5_ETL_ZAIN_KSA_D2</property>
<property name="hibernate.connection.password">ORV5_ETL_ZAIN_KSA_D2</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Code:
public class FirstExample {
public static void main(String[] args) {
Session session = null;
try {
// This step will read hibernate.cfg.xml and prepare hibernate for
// use
System.out.println(new Configuration().configure().buildSessionFactory());
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
System.out.println("se->"+session);
// 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("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
//System.out.println(e.getMessage());
} finally {
// Actual contact insertion will happen at this step
session.flush();
session.close();
}
}
}
INFO: building session factory
Exception in thread "main" java.lang.NullPointerException
at com.hibernate.test.FirstExample.main(FirstExample.java:38)Actually when the information is showing in the console , there also the information is showing as '
INFO: Configured SessionFactory: null'.
Please help.
Thanks & regards,
Kousik