hibernate 的saveOrUpdate公共方法

service类
commonDAO.saveOrUpdate(“person”);

interface CommonDAO类
public void saveOrUpdate(Object entity) throws Exception;

interface CommonDAOImpl类
@Override
public void saveOrUpdate(Object entity) throws Exception {
try{
hibernateDao.saveOrUpdate(entity);
}catch(Exception e){
log.error("保存或者更新错误", e);
throw e;
}

}

interface hibernateDao类
public void saveOrUpdate(Object obj) throws DAOException;

interface hibernateDaoImpl类
public void saveOrUpdate(List list) throws DAOException {
for (int i = 0; i < list.size(); i++) {
if (list.get(i) == null) {
throw new DAOException(new NullPointerException(
"待更新的hibernate实例为空值"));
}
getHibernateTemplate().saveOrUpdate(list.get(i));
}
}

猜你喜欢

转载自blog.csdn.net/YINZONGCHAO/article/details/79655770