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 //SessionFactory sessionFactory = ((Object)new Configuration()).configure().buildSessionFactory(); Object SessionFactory; session = ((Object)SessionFactory).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(6); contact.setFirstName("Deepak"); contact.setLastName("Kumar"); contact.setEmail("deepak_38@yahoo.com"); 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 am getting error :
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method openSession() is undefined for the type Object
at net.roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:18)