I cant say if your configuration file is invalid, atleast in theory it looks good. If you are using oracle10g as db then better use another dialect as below:
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect</property>
I just put extra if condition on session == null below to see if your session is really NULL. Also I moved session.flush() from finally into try block as below.
Code:
try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
if ( session == null ) {
System.out.println( "MY SESSION IS RETURNING NULL" );
}
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Emp emp = new Emp();
emp.setEmpNo(7999);
emp.setENAME("VIswanath");
emp.setJOB("CLERK");
emp.setMGR(7902);
emp.setHIREDATE(null);
emp.setSAL(22000.00);
emp.setCOMM(0.00);
emp.setDEPTNO(20);
session.save(emp);
System.out.println("Done");
System.out.println( "BEFORE SESSION.FLUSH....." );
// Actual contact insertion will happen at this step
session.flush(); //GETTING ERROR HERE
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
session.close();
}
}
}
Also if you can provide stack trace, it will give information as to why you are getting such problem. Its a better idea to push