Ejemplo n.º 1
0
  /** @param args */
  public static void main(String[] args) {

    Session session = HibernateUtility.getSession();
    Transaction tx = session.beginTransaction();

    EmployeePojo emp1 = new EmployeePojo();
    emp1.setEmpid(101);
    emp1.setName("aa");
    emp1.setSalary(1500.56);
    session.save(emp1);

    EmployeePojo emp2 = new EmployeePojo();
    emp2.setEmpid(102);
    emp2.setName("Rakesh");
    emp2.setSalary(2500.45);
    session.save(emp2);

    EmployeePojo emp3 = new EmployeePojo();
    emp3.setEmpid(103);
    emp3.setName("Ravi");
    emp3.setSalary(3500.566);
    session.save(emp3);

    tx.commit();
  }
Ejemplo n.º 2
0
  // 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();
    }
  }