Search code examples
javacditransactional

CDI @Transactional.rollbackOn doesn't work


I use the following source to try out @Transactional

@Transactional(value = TxType.REQUIRED, rollbackOn = { SQLException.class })
public void insert_Required() throws Exception {
    insert("INSERT_REQUIRED");
    int i = 1;
    if (i == 1) {
        throw new SQLException("error");
    }
    return;
}

private void insert(final String description) throws SQLException {
    PreparedStatement pst = connection.prepareStatement(INSERT_STMT);
    pst.setString(1, description);
    pst.execute();
}

But unfortunately the record gets inserted and committed instead of rolling back the transaction. What is wrong there?


Solution

  • Check whether AUTO_COMMIT is set to false in data source configuration in spring specific xml.