<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>
<tx:method name="find*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- applicationContext.xml哪些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allServiceMethod" expression="execution(* com.szhtp.wiki.service.impl.*.*(..))"/>
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/>
</aop:config>
//以下是com.szhtp.wiki.service.impl.WebAddMeetingServiceImpl.java,是一个webservice
@Service
public class WebAddMeetingServiceImpl implements WebAddMeetingService {
private SimpleHibernateTemplate meetingDao;
private SimpleHibernateTemplate personDao;
@Autowired
public void setSessionFactory(SessionFactory sessionFactory) {
meetingDao = new SimpleHibernateTemplate<T_ComPhone_Meeting, String>(
sessionFactory, T_ComPhone_Meeting.class);
personDao = new SimpleHibernateTemplate<T_ComPhone_Person, String>(
sessionFactory, T_ComPhone_Person.class);
}
public String addMeeting(String alterdesc,String callername,String callerphone,String callmode,String calltime,
String centrexid,String department,String hurrytype,String ternaldesc,String ternalday,String inputman,
String meetaddress,String meetman,String meetname,String meettime,String remark) { T_ComPhone_Meeting tcm=new T_ComPhone_Meeting();
tcm.setPersonname(meetmanN);
meetingDao.saveService(tcm);
try {List listtel = meetingDao.find(hql1);
String hql2 = "select id from T_ComPhone_Member where id="+ allperson[i];
T_ComPhone_Meeting tcm=new T_ComPhone_Meeting(); personDao.saveService(person);
}
}
}
// TODO Auto-generated method stub
System.out.println("成功添加会议"+"id:"+tcm.getMeetid()+"会议名:"+meetname);
return "success";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("会议添加失败");
return "error";
}
}
return "error";
}
如果在meetingDao.saveService(tcm)之后发生异常,tcm还是会插入到数据库中,怎样才能使他错误回滚呢?
[b]问题补充:[/b]
是只要在方法中catch到运行时异常才回滚,还是要使用throw抛出运行时异常才能回滚?