Transaction Management in Spring

  • Change code in employeeDao.java. employeeOperation method which is doing multiple db operations.

  • Add @Transactional Annotation on below method. Make some spelling mistake in one of query. You will see nothing will be inserted in DB.

  • Observe same code without @Transactional

  • If you do not use this annotation then successful queries will commit the records and failed queries will not means we will get partial data.

  • Remember: One transaction means everything should be successful otherwise automatically partial data will be rolled back.

Code in EmployeeDao.java as below.