Spring 的注解式事务管理:@Transactional
使用@Transactional注解
这个DAO层的事务需要抛出异常 throws Exception
@Transactional
public abstract class BaseDaoImpl<T> implements BaseDao<T>
{
@Resource
private SessionFactory sessionFactory;
protected Class<T> clazz; //
这是一个问题!
public BaseDaoImpl()
{
// 通过反射得到T的真实类型
ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
this.clazz =
(Class) pt.getActualTypeArguments()[0];
}
public Object
save(Object entity) throws Exception{
getSession().save(entity);
return entity;
}
public T
update(T entity) throws Exception{
getSession().update(entity);
return entity;
}
public void delete(Object
obj) throws Exception{
getSession().delete(obj);
}
}