/** * @author appaji * * http://www.roseindia.net * Hibernate example to inset data into Contact table */ 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(); Transaction ts=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(6); contact.setId(81); contact.setFirstName("first"); contact.setLastName("last"); contact.setEmail("ramojo");
}catch(Exception e){ System.out.println("exception occured--->"); //e.printStackTrace(); System.out.println(e.getMessage()); }finally{ // Actual contact insertion will happen at this step