Solution for to insert a record,
May 23, 2007 at 4:44 PM
Hi,
Since Hibernate is a persistence tool. It performs the operation in transactinal environment. Inorder to work the above code should me modified as.
try{ // This step will read hibernate.cfg.xml and prepare hibernate for use SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); Transaction tx=session.beginTransaction(); //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); tx.commit(); System.out.println("Done"); }catch(Exception e){ System.out.println(e.getMessage());