如何使用@Transactional?
要在controller层加事务
public ModelAndView updateFunction(HttpServletRequest request, HttpServletResponse response) throws IOException{
....................// Collect info for form1
Service.saveForm1(Form1);
....................// Collect info for form2
Service.saveForm2(Form2);
....................
}
调用两个service的方法去保存不同的form,为了一致性,希望在这里加上事务控制,要成功就一起成功,失败的话就回滚,一个也不保存。
如何在这个案例中使用@Transactional,设置哪些属性?不需要在xml文件中配置什么吧?
不要劝我将事务放在数据库或back-end。我这边局限着,只能在controller层加事务。
我很菜的,啥都不懂,请多包涵!
参考:http://static.springsource.org/spring/docs/2.0.x/reference/transaction.html
Table 9.3. @Transactional properties
Property Type Description
propagation enum: Propagation optional propagation setting
isolation enum: Isolation optional isolation level
readOnly boolean read/write vs. read-only transaction
timeout int (in seconds granularity) the transaction timeout
rollbackFor an array of Class objects, which must be derived from Throwable an optional array of exception classes which must cause rollback
rollbackForClassname an array of class names. Classes must be derived from Throwable an optional array of names of exception classes that must cause rollback
noRollbackFor an array of Class objects, which must be derived from Throwable an optional array of exception classes that must not cause rollback.
noRollbackForClassname an array of String class names, which must be derived from Throwable an optional array of names of exception classes that must not cause rollback