Transactions with Stateful Session Beans
pboddie Dec 11, 2001 11:26 AMI've been looking in lots of places for examples on how to do transactions with stateful session beans, but either the tutorials avoid the subject ("and now transactions with entity beans...") or they parrot the usual stuff about transaction attributes.
What I've done is to declare the methods of my session bean as having the "Required" transaction attribute, and then to throw an EJBException when I want the transaction rolled back. Just to make sure I get the correct behaviour, I also call setRollbackOnly on the SessionContext object provided by setSessionContext. (Actually, this last detail seems to make no difference to the behaviour I'm about to describe.)
What I get is an exception, as expected:
[FundManager] TRANSACTION ROLLBACK EXCEPTION:this.funds >= 0; nested exception is:
javax.ejb.EJBException: this.funds >= 0
But then, upon subsequent method calls on the same object I get this kind of thing:
[FundManager] TRANSACTION ROLLBACK EXCEPTION:Could not activate; nested exception is:
java.io.FileNotFoundException: D:\Software\JBoss\JBoss-2.4.3_Jetty-3.1.3-1\jboss\db\sessions\FundManager\1008087785479.ser (The system cannot find the file specified); nested exception is:
java.rmi.NoSuchObjectException: Could not activate; nested exception is:
java.io.FileNotFoundException: D:\Software\JBoss\JBoss-2.4.3_Jetty-3.1.3-1\jboss\db\sessions\FundManager\1008087785479.ser (The system cannot find the file specified)
[FundManager] java.rmi.NoSuchObjectException: Could not activate; nested exception is:
[FundManager] java.io.FileNotFoundException: D:\Software\JBoss\JBoss-2.4.3_Jetty-3.1.3-1\jboss\db\sessions\FundManager\1008087785479.ser (The system cannot find the file specified)
[FundManager] at org.jboss.ejb.plugins.AbstractInstanceCache.get(AbstractInstanceCache.java:211)
[FundManager] at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSessionInstanceInterceptor.java:194)
[FundManager] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
[FundManager] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:307)
[FundManager] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:99)
[FundManager] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
[FundManager] at org.jboss.ejb.StatefulSessionContainer.invoke(StatefulSessionContainer.java:341)
[FundManager] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:395)
[FundManager] at java.lang.reflect.Method.invoke(Native Method)
[FundManager] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
[FundManager] at sun.rmi.transport.Transport$1.run(Transport.java:152)
[FundManager] at java.security.AccessController.doPrivileged(Native Method)
[FundManager] at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
[FundManager] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:465)
[FundManager] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:706)
[FundManager] at java.lang.Thread.run(Thread.java:484)
Now, the subsequent calls all take place on a reference which is held by the client. So, I tried to do some things with getting a Handle for that reference, then getting the EJBObject, and then trying to invoke those methods. Still no luck there, either!
The big question is: does anyone else do this kind of thing, or is this all unsupported (in JBoss 2.4.3/2.4.4beta integrated with Jetty 3.1.3-1)?