Spring下的BaseHibernateDAO

package com.accp.myzf.hibernate.dao.impl;
import java.io.Serializable;
import java.util.List;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class BaseHibernateDAO extends HibernateDaoSupport {
public BaseHibernateDAO() {
}
/*
  * (non-Javadoc)
  * 
  * @see hibernate.dao.impl.IBaseHibernateDAO#add(java.lang.Object)
  */
public void add(Object item) {
  try {
   super.getHibernateTemplate().save(item);
  } catch (RuntimeException re) {
   throw re;
  }
}
/*
  * (non-Javadoc)
  * 
  * @see hibernate.dao.impl.IBaseHibernateDAO#get(java.lang.Class,
  *      java.io.Serializable)
  */
public Object get(Class clazz, Serializable id) {
  try {
   return super.getHibernateTemplate().get(clazz, id);
  } catch (RuntimeException re) {
   throw re;
  }
}
/*
  * (non-Javadoc)
  * 
  * @see hibernate.dao.impl.IBaseHibernateDAO#del(java.lang.Class,
  *      java.io.Serializable)
  */
public void del(Class clazz, Serializable id) {
  try {
   super.getHibernateTemplate().delete(this.get(clazz, id));
  } catch (RuntimeException re) {
   throw re;
  }
}
/*
  * (non-Javadoc)
  * 
  * @see hibernate.dao.impl.IBaseHibernateDAO#update(java.lang.Object)
  */
public void update(Object item) {
  try {
   super.getHibernateTemplate().update(item);
  } catch (RuntimeException re) {
   throw re;
  }
}
/*
  * (non-Javadoc)
  * 
  * @see hibernate.dao.impl.IBaseHibernateDAO#search(java.lang.Object,
  *      java.lang.Class)
  */
public List search(Object condition, Class clazz) {
  try {
   List results = getSession().createCriteria(clazz).add(
     Example.create(condition)).list();
   return results;
  } catch (RuntimeException re) {
   throw re;
  }
}
}  

 

 

 

你可能感兴趣的:(java,DAO,spring,Hibernate,orm)