Context ctx = getInitialContext();
Object ref = ctx.lookup("txiiop/StatefulSessionBean");
StatefulSessionHome home =
(StatefulSessionHome) PortableRemoteObject.narrow(
ref, StatefulSessionHome.class);
StatefulSession bean = home.create("testTxMandatory");
getLog().debug("Call txMandatoryMethod without a UserTransaction");
try
{
bean.txMandatoryMethod("without a UserTransaction");
getLog().debug("Should not get here!");
fail("TransactionRequiredException should have been thrown");
}
catch (javax.transaction.TransactionRequiredException e)
{
getLog().debug("Expected exception: " + e);
}
getLog().debug("Begin UserTransaction");
UserTransaction userTx = (UserTransaction)ctx.lookup("UserTransaction");
userTx.begin();
bean.txMandatoryMethod("within a UserTransaction");
getLog().debug("Commit UserTransaction");
userTx.commit();
bean.remove();
}