In the following code, throwing an Exception does not cancel the transaction, but throws a RuntimeException .
@Service public class HelloService { @Autowired protected CustomerRepository repository; @Transactional public void run() throws Exception { repository.save(new Customer("Jack", "Bauer")); throw new RuntimeException("Kabooom!!!");
My repository:
public interface CustomerRepository extends CrudRepository<Customer, Long> { }
Spring boot appliction.properties:
# DataSource settings: set here configurations for the database connection spring.datasource.url = jdbc:mysql://localhost/hobbadb spring.datasource.username = root spring.datasource.password = spring.datasource.driverClassName = com.mysql.jdbc.Driver
Any ideas why this is happening?
Songo source share