Hi

I am trying to play with the UserTransaction to control the CLIENT initiated 
transaction.
Client gets begins the UserTransaction first. Then it invokes the BEAN to
insert a record in the database. Since I am using a TX_BEAN_MANAGED stateful bean,
I get the UserTransaction from SessionContext. I use this user transaction to begin ()
the transaction. I am also setting AUTO COMMIT to FALSE for the connection. If
the INSERT is successful, I call UT.commit () else I call UT.rollback ().

When control is back to the client, I REMOVE the bean.

Then I try to create another instance og the same bean pointing to another database.
NOTE THAT THE UserTransaction STARTED AT CLEINT END IS NOT YET COMMITED or ROLLBACKED.

I then invoke the same method on the bean to insert another record in new
database. commit or rollback is called based on the result of the INSERT operation.

At the client end, I  either COMMIT or ROLLBACK the UserTransaction.

I AM TRYING to implement the DISTRIBUTED TRANSACTIONS here. What I had expected was
if INSERT in first database is successful but fails in the SECOND database,
exception will be thrown and since I ROLLBACK the client initiated USER TRANSACTION on
exception, whole transaction will be rolled back ( Even the insert in the FIRST 
database)

I am getting these results. Changes are still commited in the FIRST when SECOND
operation fails?

AM I DOING ANYTHING wrong here?

AM I MISSING OUT ANYTHING?

Any help/example will be greatly appretiated...

Thanks in advance for your time

Rajan Desai

PS : I have included some of the code here


I have a TX_BEAN_MANAGED STATEFUL session bean. Client gets the user transaction using 
JNDI as follows:

CLIENT :
// Note that I am using Tengah here.
    UserTransaction tx = ( UserTransaction )ctx.lookup( "javax.jts.UserTransaction" );

I start the client transaction by calling
    tx.begin ();

After this I get the home interface of my bean and call execute () method onit.
    engineHome = (SQLEngineHome)ctx.lookup ("sqlengine.SQLEngineHome");
    SQLEngine engine = engineHome.create ("TestPool2");
    engine.execute ("", iID, strName);
    engine.remove ();   // Removes the bean

    // ANOTHER instance of the bean to insert  data into SECOND DATABASE
    engineHome = (SQLEngineHome)ctx.lookup ("sqlengine.SQLEngineHome");
    SQLEngine engine = engineHome.create ("TestPool1");   // TESTPOOL 1 is used
    engine.execute ("", iID, strName);
    engine.remove ();   // Removes the bean

    // commit the transaction here. (ROLLBACK if EXCEPTION is thrown)
    tx.commit ();


SERVER BEAN :

Execute method gets the connection using POOL NAME passed to it.

    try
    {
        // IS IT SAFE TO ASSUME THAT THE CONTAINER PASSES USERTRANSACTION
        // STARTED BY THE CLIENT HERE. ??????????????????
 tx = m_SessionContext.getUserTransaction ();

 tx.begin ();

        // Pool name is passed by the client while creating the bean
        // see engine.create ("Testpool1");
        con = DriverManager.getConnection("jdbc:weblogic:jts:" + m_strPoolName );
 con.setAutoCommit (false);

 ps  = con.prepareStatement("INSERT INTO PRODUCT (PRD_PRODUCT_ID, PRD_NAME, 
PRD_DESCRIPTION) VALUES (? , ?, ?)");
 ps.setInt(1, iID);
 ps.setString(2, strName);
 ps.setString(3, "Description for " + strName );

 ps.executeUpdate();

 tx.commit ();
    }
    catch ( SQLException ex )
    {
 ex.printStackTrace ();
 tx.rollback ();
 throw new RemoteException ( ex.getMessage () );
    }



I am new to the EJB development. May be I am not very clear with the concept of EJB
and JTS? Please help :)

Thanks

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to