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.dalamar.model; import java.util.List; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.springframework.stereotype.Repository; /** * * @author Dimitar */ public class StatSnapshotDaoImpl implements StatSnapshotDao { private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @Override public void save(StatSnapshot snp) { Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); session.persist(snp); tx.commit(); session.close(); } @Override public List<StatSnapshot> list() { Session session = this.sessionFactory.openSession(); List<StatSnapshot> statSnapshots = session.createQuery("from StatSnapshots").list(); session.close(); return statSnapshots; } }