Hi all,
I'm trying to use UserTransactions in a stateful session bean to associate
itself with a transaction across several diferent methods, but it does not
work. My code is:
Stateful Session Bean:
public class TransactionBean implements SessionBean
{
private SessionContext ejbCtx;
private Entity entityRole = null;
public void setSessionContext(SessionContext context)
throws RemoteException, EJBException
{
ejbCtx = context;
}
public void ejbActivate() throws RemoteException, EJBException
{
}
public void ejbPassivate() throws RemoteException, EJBException
{
}
public void ejbRemove() throws RemoteException, EJBException
{
}
public void ejbCreate() throws CreateException, EJBException,
RemoteException
{
}
public void createEntity(String id)
{
try
{
Context context = new InitialContext();
EntityHome entityHome =
(EntityHome)PortableRemoteObject.narrow(context.lookup("java:comp/env/entity
"),
EntityHome.class);
ejbEntity = entityHome.create(id);
}
catch (Exception ne)
{
ejbEntity = null;
ne.printStackTrace();
}
}
public void setDescription(String description) throws RemoteException
{
if (ejbEntity == null)
{
throw(
new RemoteException("Entity is null, use createEntity() first"));
}
try
{
ejbEntity.setDescription(description);
}
catch (RemoteException re)
{
re.printStackTrace();
}
}
public void begin()
{
try
{
utx = ejbCtx.getUserTransaction().begin();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void commit()
{
try
{
ejbCtx.getUserTransaction().commit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void rollback()
{
try
{
ejbCtx.getUserTransaction().rollback();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
and my client is:
public class TransactionTest
{
public static void main(String[] args)
{
try
{
Context context = new InitialContext();
TransactionHome home =
(TransactionHome)PortableRemoteObject.narrow(context.lookup("java:comp/env/t
ransaction"),
TransactionHome.class);
Transaction tx = home.create();
tx.begin();
tx.createEntity("tx entity");
tx.setDescription("tx description");
tx.commit();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I'm using Orion 1.4.4 and Windows 98. I set
<transaction-type>Bean</transaction-type> in the ejb-jar.xml of Transaction
Bean and
<container-transaction>
<description/>
<method>
<description/>
<ejb-name>entity</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
for Entity bean.
When I try to use this I catch the folow exception:
java.lang.IllegalArgumentException: No active Transaction
at
com.evermind.server.ApplicationServerTransactionManager.commit(JAX)
at transaction.TransactionBean.commit(TransactionBean.java:127)
at
Transaction_StatefulSessionBeanWrapper0.commit(Transaction_StatefulSessionBe
anWrapper0.java:190)
at java.lang.reflect.Method.invoke(Native Method)
at com.evermind.server.rmi.bf.do(JAX)
at com.evermind.util.f.run(JAX)
Any ideas.
Thanks, Esteban