Hi Budi,
I emailed you recently with a suggestion.  Here's a copy in case of delivery
failure:

Have you set AutoCommit to false.  By default it is set to True in JRun.
 e.g   tConnection.setAutoCommit(false);

Also:  I think it would be a good idea to put the tx.rollback() statement
within a try catch block.


Regards
David O'Mahony
Syntegra
mailto:[EMAIL PROTECTED]



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: 11 January 2002 10:20
To: [EMAIL PROTECTED]
Subject: JRun-Talk-List V1 #40


JRun-Talk-List                 Fri, 11 Jan 2002           Volume 1 : Number
40

In this issue:

        using transaction from servlets


----------------------------------------------------------------------

Date: Fri, 11 Jan 2002 11:05:28 +0700
From: Budi Prawira <[EMAIL PROTECTED]>
Subject: using transaction from servlets
Message-ID: <[EMAIL PROTECTED]>

Has anybody ever tried to use JRun transaction service from servlets,
without any EJB?
I tried but it does not work.

I attached a sample source code, and the database script. I used JRun 3.1
with Oracle and MySQL. Both do not work, meaning that the data is committed.

The sample source code is about creating an order with three order lines.
The business process is implemented in the servlet (CreateOrderServlet), and
accessing the database is done in the data-access objects (OrderDAO and
OrderLineDAO). The transaction is set up in the servlet:

=============================================
    try {
      try {
        tx.begin();

        System.out.println("adding new order");
        orderDAO.addOrder(orderId);
        System.out.println("new order added: " + orderId);
        for (int i = 0; i < productId.length; i++) {
          System.out.println("adding new order line");
          orderLineDAO.addOrderLine(orderId,productId[i],productQty[i]);
          System.out.println("new order line added: " + productId);
        }

        tx.commit();
      } catch (DAOException daox) {
        tx.rollback();
        writeFailResponse(res,daox.getCausedByException());
        return;
      }
    } catch (Exception x) {
      writeFailResponse(res,x);
      return;
    }
========================================================

Now, on the second order line addition, a DAOException is thrown (to
simulate a database failure). When this happens, the previous transaction
must be cancelled (i.e.: the order and the first order line must be rolled
back).

When I run this servlet, and then I checked the database, the order and the
first order line are still there, meaning that they are committed.

Anyone can help?
Budi


______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm

------------------------------

End of JRun-Talk-List V1 #40
****************************
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists


********************************************************************

This email may contain information which is privileged or confidential. If you are not 
the intended recipient of this email, please notify the sender immediately and delete 
it without reading, copying, storing, forwarding or disclosing its contents to any 
other person
Thank you

Check us out at http://www.syntegra.com

********************************************************************

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to