?
Solved

Handling Transactions in java

Posted on 2007-03-20
6
Medium Priority
?
1,066 Views
Last Modified: 2013-12-19
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
Comment
Question by:dreams4ever
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
elfe69 earned 500 total points
ID: 18755981
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
 

Author Comment

by:dreams4ever
ID: 18756957
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
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 500 total points
ID: 18757070
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 18757079
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

Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question