81,118
社区成员
发帖
与我相关
我的任务
分享
<!-- 事务管理器 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:pointcut expression="execution(* cn.com.spring.modules.*.sevice..*.*(..)))" id="daoMethods"/>
<!-- <aop:pointcut expression="execution(* cn.com.spring.service..*.*(..))" id="daoMethods"/> -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods"/>
</aop:config>
public void delete(T t) {
this.getSession().delete(t);
}
public void deleteById(ID Id) {
T t = get(Id);
// if(t == null){
// return false;
// }
delete(t);
// return true;
}
@Transactional
@Override
public void saveUser(User user) {
this.userDao.save(user);
}
@Transactional
@Override
public void updateUser(User user) {
this.userDao.update(user);
}
@Override
public User getUserById(int id) {
return this.userDao.get(id);
}
@Transactional
@Override
public void deleteUserById(int id) {
this.userDao.deleteById(id);
}
@Transactional
@Override
public void deleteUser(User u) {
this.userDao.delete(u);
}