service类
commonDAO.saveOrUpdate(“person”);
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));
}
}