Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.facade; import com.resources.entity.Customer; import com.resources.entity.Module; import com.utils.MyUtils; import com.utils.Pagination; import java.io.Serializable; import java.util.logging.Level; import java.util.logging.Logger; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.criterion.Order; /** * * @author Chinsu */ public class CustomerFacade extends AbstractFacade implements Serializable { public CustomerFacade(Class entityClass) { super(entityClass); } public void setPagination(Pagination pagination) { Transaction trans = null; try { Session session = MyUtils.getSession(); if (session != null) { trans = session.beginTransaction(); Criteria cr = session.createCriteria(Customer.class); cr.setFirstResult(pagination.getFirstResult()); cr.setMaxResults(pagination.getDisplayPerPage()); cr.addOrder(pagination.isAsc() ? Order.asc(pagination.getOrderColmn()) : Order.desc(pagination.getOrderColmn())); pagination.setDisplayList(cr.list()); trans.commit(); } } catch (Exception e) { try { if (trans != null && trans.isActive()) { trans.rollback(); } } catch (Exception ex) { throw ex; } Logger.getLogger(Module.class.getName()).log(Level.SEVERE, null, e); } } }