0

I have a program that uses handler, businessObject and DAO for program execution. Control starts from handler to businessObject and finally to DAO for Database operations.

For example my program does 3 operations: insertEmployee(), updateEmployee() and deleteEmployee() every method being called one after the other from handler. once insertEmployee() called control get back to handler then it calls updateEmployee() again control back to handler then it calls deleteEmployee().

Problem Statement: If my first two methods in dao are successful and control is back to handler and next method it request to dao is deleteEmployee(). Meanwhile it faces some kind of exception in deleteEmployee(). It should be able to rollback the earlier insertEmployee() and updateEmployee() operation also. It should not rollback only deleteEmployee(). It should behave as this program never ran in system.

Can any one point me how to achieve this in spring jdbcTemplate Transaction management.

Rohan K
  • 177
  • 1
  • 3
  • 21
  • http://www.journaldev.com/2603/spring-transaction-management-example-with-jdbc – Panther Jul 22 '15 at 06:44
  • @Panther not helping when my db operation are on multiple tables. The shared link works good for one table. Also in comment section other users had faced same problem. Thanks for looking in to it. – Rohan K Jul 22 '15 at 06:48
  • You may consider making connection autocommit off and then commit or rollback from java after all the operations. – Panther Jul 22 '15 at 06:51

1 Answers1

0

You should check about transaction propagation, in special: PROPAGATION_REQUIRED.

More info: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html#tx-propagation

Gonz
  • 1,198
  • 12
  • 26