Hi,

CreateException thrown in ejbCreate does not find its way to the bean's
client. Instead, the client
gets the following exception:
//-BEGIN
java.rmi.ServerException: RemoteException occurred in server thread;
nested exception is:
        java.rmi.RemoteException: Container cannot commit a transaction;
nested exception is:
        javax.transaction.RollbackException
//-END

This exception is generated, if the INSERT in ejbCreate (included below
in this message) violates
a unique key constraint (for example).

After looking at the trace and the JOnAS source code, I had the
impression that somehow the
"entityContext.setRollbackOnly()" instruction is ignored (the execution
gets into the
"rctx.mustCommit()" branch in JEntityHome.postInvoke), but I am not
sure, since I am not familiar
enough with the architecture of JOnAS. Anyway, I think that the client
must get the
CreateException, if the EntityBean.ejbCreate throws it. Please, correct
me if I am wrong.

Peter

The bean method is:
//-BEGIN
    public AccountBeanPK ejbCreate(int val_accno, String val_customer,
double val_balance)
 throws CreateException {

 // Init object state
 accno = val_accno;
 customer = val_customer;
 balance = val_balance;

 // Create the primary key
 AccountBeanPK pk = new AccountBeanPK(val_accno);

 try {
     // get a connection for this transaction context
     Connection conn = getConnection();

     // create object in DB
     PreparedStatement stmt = conn.prepareStatement("insert into
accountsample (accno, customer, balance) values (?, ?, ?)");
     stmt.setInt(1, pk.accno);
     stmt.setString(2, customer);
     stmt.setDouble(3, balance);
     stmt.executeUpdate();

     // close statement
     stmt.close();

     // release connection
     conn.close();

 } catch (SQLException e) {
            e.printStackTrace() ;
            System.err.println( "Error code: "+e.getErrorCode() ) ;
            entityContext.setRollbackOnly() ;
     throw new CreateException("Failed to create bean in database");
 }

 // Return the primary key
 return pk;
    }
//-END

On the server side the following trace has been produced:
//-BEGIN
[...]
 SubCoordinator.addResource: new datasource
XAResource ---> START org.objectweb.jonas.jdbc_xa.XAResourceImpl@7297e7
Xid = 1004216701223937
ConnectionImpl.prepareStatement(String insert into accountsample (accno,
customer, balance) values
 (?, ?, ?))
 EJBContextImpl.setRollbackOnly()
 Current.setRollbackOnly()
 TransactionImpl.setRollbackOnly()
 SubCoordinator.setRollbackOnly()
 JEntityHome.postinvoke
 postInvoke: Committing transaction
 Current.commit()
 Detach Thread from Tx
 TransactionImpl.commit()
 SubCoordinator.commit_one_phase()
 SubCoordinator.doBeforeCompletion()
 TransactionImpl.unsetTimer()
 TimerEvent.unset
 SubCoordinator.doRollback()
XAResource ---> ROLLBACK
org.objectweb.jonas.jdbc_xa.XAResourceImpl@7297e7
Xid = 1004216701223937
XAResource ---> rollback: XA START without XA END
 SubCoordinator.doAfterCompletion()
 EntityContextImpl.afterCompletion: Status= 4
NamingManager: setComponentContext: AccountExpl
NamingManager: setComponentContext: AccountExpl
 EntityContextImpl.afterCompletion: remove object
 getPrimaryKey -> null
 JEntityHome.removeEJBObject: pk = null
 JBeanEntity.releaseContext
 releaseICtx IT
 releaseICtx IT: NOTIFY
 JBeanEntity: putContextInPool
 JBeanHome.toThePool: size=1
ConnectionManager.endTransaction
  Pool: free a Connection for this Tx
WARNING: Connection not closed by caller
Force a physical close to avoid reusing it in another transaction
XAConnectionImpl.close()
 Remove Tx from Xid:1004216701223937
 Commit local transaction -> rolled back!
//-END

----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".

Reply via email to