File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Web Transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Web Transaction" Watch "Web Transaction" New topic
Author

Web Transaction

Usera User
Greenhorn

Joined: Jul 13, 2005
Posts: 21
How to handle transaction across serveral web pages?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

This is coming from a bit of a Hibernate background, but one of the things we use is Open Session in View.

In this type of scenario, we use a Servlet filter, or a transaction interceptor, that starts a transaction as the web request comes in. When the response is about to be sent to the client, the transaction is committed. It is very easy, very simple, and fundamentally, it works!

There are often initial objections regarding the lenght of the transaction, or the merit of keeping it open for the duration of the request-response cycle. Most of those objections can be alleviated when you actually look at the metrics of the operation.

Multi-tier transactions can make this a bit yucky, but for many applications, this is a very functional practice.

-Cameron McKenzie
Usera User
Greenhorn

Joined: Jul 13, 2005
Posts: 21
Hi Cameron McKenzie,

Thanks for your prompt response.

Do you mean I can write a custom transaction manager using servlet filter, which starts the transaction on first page web request come in and then commit the transaction on the second page response?

I think single transaction scope across multiple independent web requests is very difficult implement. Would you please give me more hints how to implement it? e.g. how to get the same datasource across multiple independent web requests whe the server is using the connection pooling?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Well, again, I'm coming at it from a Hibernate perspective, so my perspective is skewed a bit towards that type of an implementation. I don't want to lead you down the wrong path.

Some people that are much smarter and much better looking than me have written about it in the following tuotrial. This will answer many of your questions, and at least give you a persective on how the Hibernate community deals with this issue:

Hibernate Open Session In View Pattern and Transaction Management

-Cameron McKenzie
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Originally posted by Calvin Wong:
How to handle transaction across serveral web pages?

Not to change the topic, but are you sure this is the real requirement? Sometimes people want a logical transaction, but not an actual lock. For example, what happens if someone leaves your website while in a transaction?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Usera User
Greenhorn

Joined: Jul 13, 2005
Posts: 21
Hi Jeanne Boyarsky,

I need to migrate the client-server based POS (which is using PowerBuilder) to web-based POS.

The old system has many business logics and validations on the database level (plsql), the inventory records is locked when user inputted the invoice, and the invoice was inputted across several screens and committed before printing the invoice.

On the new web system, we want to keep the existing db logics.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Web Transaction
 
Similar Threads
How to specify a Transaction Timeout in a Web Application
Dreamcar assignment for Part II
web services and transactions
WA #1.....word association
using JDBCTemplate in Spring How to prove connection object has been closed ?