/** @param args */ public static void main(String[] args) { Session session = HibernateUtility.getSession(); Transaction tx = session.beginTransaction(); EmployeePojo emp1 = new EmployeePojo(); emp1.setName("Ramu"); emp1.setSalary(1500); session.save(emp1); EmployeePojo emp2 = new EmployeePojo(); emp2.setName("Rakesh"); emp2.setSalary(2500); session.save(emp2); EmployeePojo emp3 = new EmployeePojo(); emp3.setName("Ravi"); emp3.setSalary(3500); session.save(emp3); tx.commit(); session.close(); }
// public static void main(String[] args) public void create() { try { Session session = HibernateUtility.getSession(); Context ctx = new InitialContext(); UserTransaction tx = (UserTransaction) ctx.lookup("java:comp/UserTransaction"); tx.begin(); // Transaction tx=session.beginTransaction(); EmployeePojo emp1 = new EmployeePojo(); emp1.setEmpid(102); emp1.setName("shamu"); emp1.setSalary(1500); session.save(emp1); EmployeePojo emp11 = new EmployeePojo(); emp11.setEmpid(103); emp11.setName("nama"); emp11.setSalary(2500); session.save(emp11); emp11.setSalary(6000); session.flush(); tx.commit(); // tx.commit(); session.close(); } catch (Exception e) { e.printStackTrace(); } }