//creating a new session object Session session = HibernateUtil.getSessionFactory().openSession(); //creating Student object Student student = new Student("John", "Doe", "[email protected]"); //saving student object to the database session.saveOrUpdate(student);
//creating a new session object Session session = HibernateUtil.getSessionFactory().openSession(); //retrieving student object Student student = session.get(Student.class, 1L); //updating student object student.setFirstName("Jane"); //saving updated student object to the database session.saveOrUpdate(student);Package Library: org.hibernate.Session saveOrUpdate() method belongs to the Hibernate framework package library.