Announcement Announcement Module
No announcement yet.
Unable to rollback transaction for a runtime exception thrown. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to rollback transaction for a runtime exception thrown.

    I have a problem with spring declarative transaction management i.e i am unable to rollback the transaction after the error has been caught.

    My idea was to develop a spring method to rollback a transaction after which a runtime exception has been thrown explicitly by me. I was struct here from 5 days .

    Can any

    The configurations i have made area as follows :


    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="sysDataSource"/>

    ConfParamsControllermy controller where i called the update method)

    @Transactional(isolation=Isolation.DEFAULT,propaga tion=Propagation.REQUIRES_NEW,rollbackFor=Throwabl e.class )
    @RequestMapping(value="/editParam", method=RequestMethod.POST)
    public String _P_update_param(@ModelAttribute("confParam")ConfPa ramDTO dto, BindingResult result, Model m){"inside _P_update_param()");
    paramValidator.validate(dto, result);
    String formView = "";
    if (result.hasErrors()) {
    dto = confParamDAOImpl.viewConfParam(dto.getId());
    formView = "paramUpdateForm";
    } else {

    throw new RuntimeException("an runtime exception is explicitly thrown");
    }catch(DataAccessException e){
    System.out.println("Error in creating record, rolling back");
    throw e;
    m.addAttribute("confParams", getParamsList());
    formView = "paramsList";
    }"Exiting From the _P_update_param() method");
    return formView;

    Log file:

    12:12:12,249 DEBUG JdbcTemplate:810 - Executing prepared SQL update
    12:12:12,265 DEBUG JdbcTemplate:569 - Executing prepared SQL statement [UPDATE sys_conf_params_t SET conf_param_nm = ?, conf_param_desc = ?, conf_param_val = ?, updtd_dt = ?, updtd_by = ? WHERE conf_param_id = ?]
    12:12:12,272 DEBUG DataSourceUtils:110 - Fetching JDBC Connection from DataSource
    12:12:12,278 DEBUG DataSourceUtils:114 - Registering transaction synchronization for JDBC Connection
    12:12:12,296 DEBUG JdbcTemplate:819 - SQL update affected 1 rows
    12:12:15,179 DEBUG DataSourceUtils:332 - Returning JDBC Connection to DataSource
    12:12:15,180 DEBUG DataSourceTransactionManager:844 -Initiating transaction rollback
    12:12:15,184 DEBUG DataSourceTransactionManager:279 - Rolling back JDBC transaction on Connection [jdbc:mysql://, UserName=***********, MySQL Connector Java]
    12:12:15,189 DEBUG DataSourceTransactionManager:322 - Releasing JDBC Connection [jdbc:mysql://, UserName=***********, MySQL Connector Java] after transaction
    12:12:15,190 DEBUG DataSourceUtils:332 - Returning JDBC Connection to DataSource
    12:12:15,191 DEBUG ExceptionHandlerExceptionResolver:132 - Resolving exception from handler [public java.lang.String ate_param(,org.springf ramework.validation.BindingResult,org.springframew ork.ui.Model)]: java.lang.RuntimeException: an runtime exception is explicitly thrown
    12:12:15,199 DEBUG ExceptionHandlerExceptionResolver:273 - Invoking @ExceptionHandler method: public org.springframework.web.servlet.ModelAndView ptionHandler(java.lang.Exception)