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.qfix.vms.dao.impl; import com.qfix.vms.dao.AbstractDao; import com.qfix.vms.dao.PaymentsDao; import com.qfix.vms.model.Payments; import java.io.Serializable; import java.security.NoSuchAlgorithmException; import java.sql.Date; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.springframework.stereotype.Repository; /** * * @author Ruwani Jayarathna */ @Repository("paymentsDao") public class PaymentsDaoImpl extends AbstractDao<Serializable, Payments> implements PaymentsDao { @SuppressWarnings("unchecked") @Override public void savePayments(Payments payments) { persist(payments); } @Override public List<Payments> findAllPayments() { Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Payments> payments = (List<Payments>) criteria.list(); return payments; } @Override public List<Payments> findPayments(Date from, Date to) { Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(Payments.class); cr.add(Restrictions.between("date", from, to)); List payments = cr.list(); return payments; } @Override public List<Payments> vehicleReport(Date from, Date to) { Session session = sessionFactory.openSession(); Transaction tx = null; tx = session.beginTransaction(); Criteria cr = session.createCriteria(Payments.class); cr.add(Restrictions.between("date", from, to)); List payments = cr.list(); return payments; } }