I have implemented a class where i need to insert some data into a database but the insert must rollback if something goes wrong. Once i have performed the insert i throw an exception to test the rollback, but once i check the database, the rows are inserted, which means rollback never happened.
import org.springframework.transaction.annotation.Transactional;
public class SomeClass{
@Autowired
private JdbcTemplate jdbcTemplate;
@Transactional
public void insertToDb() throws Exception{
String sql = "INSERT STUFF"
jdbcTemplate.update(sql);
throw new Exception();
}
}