//完善HibernateUtil方法
public static void add(Object entity){
Session s = null;
Transaction tx = null;
try{
s = HiberanteUtil.getSession();
tx = s.beginTransaction();
s.save(entity);
tx.commit();
}finally{
if(s!=null){
s.close();
}
}
}
public static void update(Object entity){
Session s = null;
Transaction tx = null;
try{
s = HiberanteUtil.getSession();
tx = s.beginTransaction();
s.update(entity);
tx.commit();
}finally{
if(s!=null){
s.close();
}
}
}
public static void delete(Object entity){
Session s = null;
Transaction tx = null;
try{
s = HiberanteUtil.getSession();
tx = s.beginTransaction();
s.delete(entity);
tx.commit();
}finally{
if(s!=null){
s.close();
}
}
}
public static Object get(Class clazz, Serializable id){
Session s = null;
try{
s = HiberanteUtil.getSession();
Object obj = s.get(clazz,id);
return obj;
}finally{
if(s != null){
s.close();
}
}
}
JavaWeb学习笔记-Hibernate-03-完善HibernateUtil
最新推荐文章于 2020-08-28 15:10:42 发布