• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1073
  • Last Modified:

Handling Transactions in java

It is basically a application in struts. For a specific functionality, it navigates through 5 pages. It involves 4 database tables. in everypage, there are data inserts in the tables and also updates. The issue is, if there is some error in the final page, all the prior transactions should rollback, which is not happening.
I am carrying the same connection throughout this session. The inserts has to happen in the intermediate pages as based on the insert row, a id will be generated and that id is used in the other manipulations for the remaining pages. Pls suggest me how can i acheive a rollback if for any exceptions in the intermediate / final pages.
Pls respond ASAP, its urgent. Thanks
0
dreams4ever
Asked:
dreams4ever
  • 2
2 Solutions
 
elfe69Commented:
It is really not a good idea to keep a database transaction between several web pages because you will never know if the client leaves your pages and jump to any other site. In such a case, your transaction could stay pending for hours...
I think the best way to achieve such multi-pages insertion/update process is to store everything in temporary tables with the sessionID or any other ID and only when the last page is processed to move everything to the production tables
0
 
dreams4everAuthor Commented:
Hi
Thanks for the suggestion and you are absolutely correct.  but unfortunately the project is in such a stage where it cannot go back for creating temp db tables etc. Is there any otherway other than that to solve this issue ?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Yes, you should probably store the information in memory (maybe in Hashtables) of the web application (HttpSession object), and insert them in a bulk when ready. You will run into problems if you keep the connection open for long and if the user gets disconnected through a network time out or something of that sort.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Its not required to store it in temp DB tables - I think memory would do but yeah, you need to ensure it is cleaned in case of exceptions otherwise the memory usage will go high.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now