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
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to