コード例 #1
0
 /*
  * retrieves all customers from db
  *
  * @return List of customers
  */
 public List<Student> selectAll() {
   SessionFactory sessionFactory = HibernateSession.getSessionFactory();
   Session session = sessionFactory.openSession();
   List<Student> customers = session.createCriteria(Student.class).list();
   session.close();
   return customers;
 }
コード例 #2
0
 /*
  * selects one customer by Id
  *
  * @param id
  *
  * @return Customer
  */
 public Student selectById(Long id) {
   SessionFactory sessionFactory = HibernateSession.getSessionFactory();
   Session session = sessionFactory.openSession();
   Student customer = (Student) session.get(Student.class, id);
   session.close();
   return customer;
 }
コード例 #3
0
 /*
  * delete given customer
  *
  * @param customer to delete
  */
 public void delete(Student customer) {
   SessionFactory sessionFactory = HibernateSession.getSessionFactory();
   Session session = sessionFactory.openSession();
   session.beginTransaction();
   session.delete(customer);
   session.getTransaction().commit();
   session.close();
 }
コード例 #4
0
 /*
  * inserts a new customer in database retrieves generated id and sets to
  * customer instance
  *
  * @param new customer
  */
 public void insert(Student customer) {
   SessionFactory sessionFactory = HibernateSession.getSessionFactory();
   Session session = sessionFactory.openSession();
   session.beginTransaction();
   Long id = (Long) session.save(customer);
   customer.setId(id);
   session.getTransaction().commit();
   session.close();
 }