您的位置:首页 > 数据库

hibernate对数据库的简单操作

2015-07-17 15:07 561 查看
import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.iman.dao.base.BaseDao;

public class BaseDaoImpl extends HibernateDaoSupport implements BaseDao{

public boolean save(Object obj) throws Exception{
try {
this.getHibernateTemplate().save(obj);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

public boolean update(Object obj) throws Exception{
try {
this.getHibernateTemplate().update(obj);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

public boolean saveOrUpdate(Object obj) throws Exception{
try {
this.getHibernateTemplate().saveOrUpdate(obj);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}

}

public boolean saveOrUpdateAll(List<?> list) throws Exception{
try {
this.getHibernateTemplate().saveOrUpdateAll(list);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}

}

public Object get(Class<?> className, Serializable id)throws Exception{
return getHibernateTemplate().get(className, id);
}

public boolean delete(Object object) throws Exception{
try {
this.getHibernateTemplate().delete(object);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

public boolean deleteAll(List<?> ls) throws Exception{
try {
this.getHibernateTemplate().deleteAll(ls);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: