Hi,
In a create method of a statefull session bean I try
to do context.getEJBObject().
It returns the expected object, but when I later try
to use it, I get:
[MySession] TRANSACTION ROLLBACK EXCEPTION:Can't get an object with a null key; nested
exception is:
java.lang.IllegalArgumentException: Can't get an object with a null key
[MySession] java.lang.IllegalArgumentException: Can't get an object with a null key
[MySession] at
org.jboss.ejb.plugins.AbstractInstanceCache.get(AbstractInstanceCache.java:70)
[MySession] at
org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSessionInstanceInterceptor.java:154)
[MySession] at
org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
[MySession] at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:263)
[MySession] at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:99)
[MySession] at
org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
[MySession] at
org.jboss.ejb.StatefulSessionContainer.invoke(StatefulSessionContainer.java:326)
[MySession] at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:441)
[MySession] at
org.jboss.ejb.plugins.jrmp.interfaces.StatefulSessionProxy.invoke(StatefulSessionProxy.java:150)
[MySession] at $Proxy17.myMethod(Unknown Source)
(Please ignore line numbers: This is an older version,
but the latest CVS seems to have the same problem.)
The javadoc for SessionContext.getEJBObject() says:
"An instance of a session enterprise Bean can call this
method at anytime between the ejbCreate() and ejbRemove()
methods, including from within the ejbCreate() and
ejbRemove() methods."
So this looks like a bug in JBoss.
It looks to me as if the proxy returned does
not have any (internal, JBoss-specific) identity,
as it is supposed to. Thus the above exception.
When looking at ...ejb.plugins.StatefulSessionFilePersistenceManager
method createSession(), the identity is not set
until after a successfull return from the bean
create method. A check for non-null identity is
used elsewhere to free the instance in case of
a failed create() call.
To fix, I an considering to move the assignment
of the identity to _before_ the ejbCreate() call,
and reset the identity to null in case of an
exception thrown from the ejbCreate() method.
Unless somebody sees any problems with this, I'll
commit this change one of these days.
Best Regards,
Ole Husgaard.