Java user-defined transaction management not working correctly???
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sasuke_Uchiha
Posted On:   Thursday, May 29, 2003 12:15 AM

Hi everyone, I have encountered a problem when using Java user-defined transaction management in my session bean. It threw an exception but I could not work out what that means. Could anyone comment on this? Thanks. This BrokerBean is a stateless session calling other entities bean to perform some simple operations. There are 2 Cloudscape databases in use. Invoices (EB) use InvoiceDB and all the other EBs use StockDB. If I comment out the user-defined transaction management code, then everything works fine. Or if I comment out the Invoices EB code, it is fine as well. It seemed to me that there is something wrong in transaction management when dealing with distributed databases. --------------- sour   More>>

Hi everyone,

I have encountered a problem when using Java user-defined transaction management in my session bean. It threw an exception but I could not work out what that means. Could anyone comment on this? Thanks.


This BrokerBean is a stateless session calling other entities bean to perform some simple operations. There are 2 Cloudscape databases in use. Invoices (EB) use InvoiceDB and all the other EBs use StockDB.


If I comment out the user-defined transaction management code, then everything works fine. Or if I comment out the Invoices EB code, it is fine as well. It seemed to me that there is something wrong in transaction management when dealing with distributed databases.


--------------- source code ----------------------


public void CreateInvoices(int sub_accno) {

try {

utx = context.getUserTransaction();

utx.begin();



SubAcc subAcc = subAccHome.findByPrimaryKey(new SubAccPK(sub_accno));

String sub_name = subAcc.getSubName();

String sub_address = subAcc.getSubAddress();



Collection c = stockTransHome.findBySubAccno(sub_accno);

Iterator i = c.iterator();



ArrayList a = new ArrayList();



while (i.hasNext()) {

StockTrans stockTrans = (StockTrans)i.next();

int trans_id = stockTrans.getTransID();

String tran_type = stockTrans.getTranType();

int stock_id = stockTrans.getStockID();

float price = stockTrans.getPrice();



Invoices invoices = invoicesHome.create(sub_accno, sub_name, sub_address, trans_id, stock_id, tran_type, price);

stockTrans = stockTransHome.findByPrimaryKey(new StockTransPK(trans_id));

stockTrans.remove();

}



utx.commit();

utx = null;



} catch (Exception e) {



if (utx != null) {

try {

utx.rollback();

utx = null;

}

catch (Exception ex) {}

}



// e.printStackTrace();

throw new EJBException("BrokerBean.CreateInvoices(): " + e.getMessage());

}

}



--------------- exception ----------------------



Initiating login ...

Enter Username:

Enter Password:

Binding name:`java:comp/env/ejb/BrokerSB`

EJB test succeed

Test BuyStock!

Test BuyStock!

Test BuyStock!

Test BuyStock!

Test SellStock!

Test SellStock!

Caught an exception.

java.rmi.ServerException: RemoteException occurred in server thread; nested exce
ption is:

java.rmi.RemoteException: BrokerBean.CreateInvoices(): CORBA TRANSACTION
_ROLLEDBACK 9998 Maybe; nested exception is:
org.omg.CORBA.TRANSACTION_ROLLEDBACK: vmcid: 0x2000 minor code: 1806
completed: Maybe
at com.sun.corba.ee.internal.iiop.ShutdownUtilDelegate.mapSystemExceptio
n(ShutdownUtilDelegate.java:64)
at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
at _Broker_Stub.CreateInvoices(Unknown Source)
at Client.main(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:22
9)
at com.sun.enterprise.appclient.Main.main(Main.java:155)
Caused by: java.rmi.RemoteException: BrokerBean.CreateInvoices(): CORBA TRANSACT
ION_ROLLEDBACK 9998 Maybe; nested exception is:
org.omg.CORBA.TRANSACTION_ROLLEDBACK: vmcid: 0x2000 minor code: 1806
completed: Maybe
at com.sun.enterprise.iiop.POAProtocolMgr.mapException(POAProtocolMgr.ja
va:389)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:43
1)
at BrokerBean_EJBObjectImpl.CreateInvoices(BrokerBean_EJBObjectImpl.java
:265)
at _BrokerBean_EJBObjectImpl_Tie._invoke(Unknown Source)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(Ge
nericPOAServerSC.java:520)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(Gen
ericPOAServerSC.java:210)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAS
erverSC.java:112)
at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProces
sor.java:84)

at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadP

ool.java:99)

   <<Less

Re: Java user-defined transaction management not working correctly???

Posted By:   Shane_Linley  
Posted On:   Wednesday, June 4, 2003 10:57 PM

I encountered this problem as well when trying to run a JUnit test under WebSphere Studio Application Developer (WSAD) 5 that obtains a WSAD WAS 4 Test Server database connection from a configured datasource.



I was able to solve it by changing the default JRE I was using to a WebSphere v4 JRE. Follow these steps:



1. Open WSAD Preferences (Window->Preferences)

2. Navigate to Java->Installed JRE's

3. Check the Websphere v4 or WebSphere v5 JRE option

4. Let your projects be rebuilt, stop and start your severs as appropriate and run your JUnit test again.


I re-ran the test and was able to obtain the database connection.



Regards,
Shane
About | Sitemap | Contact