I am new in Hibernate. I am getting sessionfactory object as null. But the configuration in hibernate.cfg.xml file seems to be ok.
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("
[email protected]");
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();
}
}
}
Actually when the information is showing in the console , there also the information is showing as '
.
Please help.