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.


Ready for structured training?

Learn Java Full Stack with real projects

Live classes, practical projects, interview preparation and placement support in one guided programme.

View Java Full Stack Course Book Free Demo