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.mycompany.CRMFly.hibernateAccess; import com.mycompany.CRMFly.entities.Organisations; import com.mycompany.CRMFly.entities.Payments; import java.util.List; import org.hibernate.SessionFactory; import org.hibernate.criterion.Disjunction; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; /** * * @author ?? */ @Repository public class PaymentsDAOImpl implements PaymentsDAO { @Autowired private SessionFactory sessionFactory; @Override public void addPayment(Payments payment) { sessionFactory.getCurrentSession().save(payment); } @Override public List<Payments> listPayments() { return sessionFactory.getCurrentSession().createQuery("from com.mycompany.CRMFly.entities.Payments").list(); } @Override public void removePayment(Payments payment) { if (null != payment) { payment = (Payments) sessionFactory.getCurrentSession().get(Payments.class, payment.getId()); sessionFactory.getCurrentSession().delete(payment); } } @Override public void changePayment(Payments payment) { sessionFactory.getCurrentSession().update(payment); } @Override public Payments getPaymentForId(Long id) { // return (Payments) sessionFactory.getCurrentSession(). // load(Payments.class, id); return (Payments) sessionFactory.getCurrentSession().get(Payments.class, id); } @Override public List<Payments> getAllPayments() { return sessionFactory.getCurrentSession().createCriteria(Payments.class).list(); } @Override public Organisations getBank(Long id) { Payments payment = (Payments) sessionFactory.getCurrentSession().get(Payments.class, id); return payment.getBank(); } public List<Payments> getFromProxy(List<Payments> proxy) { Disjunction or = Restrictions.disjunction(); for (Payments pr : proxy) { or.add(Restrictions.eq("id", pr.getId())); } return sessionFactory.getCurrentSession().createCriteria(Payments.class).add(or).list(); } }