I have annotated my a service method (meaning it is annotated with @RequestMapping) with @Transactional(readOnly=false), i.e. this method has two annotations: @RequestMapping and @Transactional.
In the method, I explicitly throw a new RuntimeException() by catching unchecked exceptions bubbled up, just to be sure that a rollback can be triggered in case it is needed.
The method functions correctly in my test cases, until the cases created for testing transaction management. One of such case is to fail an database insert statement, in which a database (jdbcTemplate) error did occur, caught by the method, and a RuntimeException was thrown.
This piece of code works when I tested in a standalone environment (Eclipse, test run started by a "main" in the class). However, rollback did not occur in a server environment, where the method was executed by a web service call (recall that it is annotated by @RequestMapping). In fact, I could not detect any sign in my log (I use log4j) on server that transaction management is working in the server environment.
My server runs jboss 6 (an Openshift environment).
Because differences in standalone and server environments ("main block" v.s. web service call, and different dataSource defns), two different applicationContext.xml were used. I did make sure that two contexts are identical w.r.t transaction management, i.e. "txManager" definition, and "tx:annotation-driven" statement.
Any advice on possible causes, and/or "what/where to check" are greatly appreciated.
Best Regards,
John
code segment (modified for clarity)
In the method, I explicitly throw a new RuntimeException() by catching unchecked exceptions bubbled up, just to be sure that a rollback can be triggered in case it is needed.
The method functions correctly in my test cases, until the cases created for testing transaction management. One of such case is to fail an database insert statement, in which a database (jdbcTemplate) error did occur, caught by the method, and a RuntimeException was thrown.
This piece of code works when I tested in a standalone environment (Eclipse, test run started by a "main" in the class). However, rollback did not occur in a server environment, where the method was executed by a web service call (recall that it is annotated by @RequestMapping). In fact, I could not detect any sign in my log (I use log4j) on server that transaction management is working in the server environment.
My server runs jboss 6 (an Openshift environment).
Because differences in standalone and server environments ("main block" v.s. web service call, and different dataSource defns), two different applicationContext.xml were used. I did make sure that two contexts are identical w.r.t transaction management, i.e. "txManager" definition, and "tx:annotation-driven" statement.
Any advice on possible causes, and/or "what/where to check" are greatly appreciated.
Best Regards,
John
code segment (modified for clarity)
Code:
@RequestMapping(value="billerConfigUpdate", method=RequestMethod.POST,
produces="application/json", consumes="application/json")
@Transactional(readOnly=false, propagation=Propagation.REQUIRED, isolation=Isolation.READ_COMMITTED)
public @ResponseBody ActivityStatus billerConfigUpdate(@RequestBody String req_body) {
ActivityStatus ac = new ActivityStatus();
try {
configUpdate(....); /* database ops are in this plain, i.e. unannotated, java method */
} catch (RuntimeException rte) {
logger.error("Error in billerConfigUpdate -- transaction rollback " + rte.getMessage());
throw new RuntimeException();
}
return ac;
}