Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 ac.dia.dao;
- import ac.dia.util.HibernateUtil;
- import java.io.Serializable;
- import java.util.List;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- /**
- *
- * @author user1
- * @param <T>
- * @param <ID>
- */
- public abstract class GenaricDAO<T, ID extends Serializable> {
- Session session = HibernateUtil.getSessionFactory().openSession();
- T obj;
- public void saveData(T obj) throws Exception {
- Transaction t = session.beginTransaction();
- session.save(obj);
- t.commit();
- }
- public void updateData(T obj) throws Exception {
- Transaction t = session.beginTransaction();
- session.update(obj);
- t.commit();
- }
- public void deleteData(T obj) throws Exception {
- Transaction t = session.beginTransaction();
- session.delete(obj);
- t.commit();
- }
- public T findData(Class c, ID id) throws Exception {
- return (T) session.get(c, id);
- }
- public List<T> getAllData(Class c) throws Exception {
- return (List<T>) session.createCriteria(c).list();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement