Solved insertion problem.,
July 12, 2009 at 9:17 AM
I finaly got the row permanently inserted into the database.
I changed my FirstExample.java code to the following.
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 = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); 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(4); contact.setFirstName("Deepak"); contact.setLastName("Kumar"); contact.setEmail("deepak_38@yahoo.com"); session.save(contact); System.out.println("Done"); session.getTransaction().commit(); }catch(Exception e){ System.out.println(e.getMessage()); }finally{ // Actual contact insertion will happen at this step session.flush(); session.close();