Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SessionBean uses SessionBean => ClassCastException

3 views
Skip to first unread message

Carsten Jakobsen

unread,
Feb 4, 2000, 3:00:00 AM2/4/00
to
I'm having a lot of trouble "calling" one Session Bean (or Entity Bean for
that matter) from another Session Bean. I keep getting ClassCastExceptions
when I do a myBean = BeanHome.create(). The calling SB does a normal jndi
lookup as if it was a normal client - as follows:

private IDGeneratorHome serviceLookup()
{
IDGeneratorHome result = null;
try
{
Context ctx = new InitialContext();
Object ref = ctx.lookup("java:comp/Waves/IDGenerator");
result = (IDGeneratorHome)
PortableRemoteObject.narrow(ref,IDGeneratorHome.class);
} catch(Exception ex) { ex.printStackTrace(); }

return (result);
}

I do not think that this code is the problem as I get the exception before
calling the above method. I get it as soon as the calling bean is doing a
"myCaller = callerHome.create();".

I the concrete sample I try to use a "Unique Key Generator" from within a
BMP SessionBean which can create one or more keywords in a table like (ID
number(4), Keyword varchar2(200)).

The really funny thing is that it actually works once in a while. Once I had
it working so that every second time it worked (gave an unique ID) and every
second time I got the below exception. I did not kill the client between the
calls.

Oh, I did remember to include the IDGenerator in the calling session beans
DD (EJB references).

Any ideas ?

Carsten

The full output from the ejbContainer log shows:

[today] stderr: java.lang.ClassCastException:
waves.primarykey.IDGeneratorHomePOAInvokeHandler
[today] stderr: at
waves.primarykey._IDGeneratorHome_Stub.create(_IDGeneratorHome_Stub.java:53)
[today] stderr: at
waves.util.KeywordAdminBean.addKeyword(KeywordAdminBean.java:82)
[today] stderr: at java.lang.reflect.Method.invoke(Native Method)
[today] stderr: at
com.inprise.ejb.ConcreteMethod.invoke(ConcreteMethod.java:24)
[today] stderr: at com.inprise.ejb.EJBContext.invoke(EJBContext.java:149)
[today] stderr: at
com.inprise.ejb.Dispatcher.doInvoke(Dispatcher.java:1029)
[today] stderr: at com.inprise.ejb.Dispatcher.invoke(Dispatcher.java:518)
[today] stderr: at com.inprise.ejb.Dispatcher.invoke(Dispatcher.java:494)
[today] stderr: at com.inprise.ejb.Dispatcher.invoke(Dispatcher.java:227)
[today] stderr: at
waves.util.KeywordAdminPOAInvokeHandler.addKeyword(KeywordAdminPOAInvokeHand
ler.java:42)
[today] stderr: at
waves.util.KeywordAdminPOAInvokeHandler.addKeyword(KeywordAdminPOAInvokeHand
ler.java:77)
[today] stderr: at
waves.util.KeywordAdminPOA._invoke(KeywordAdminPOA.java:71)
[today] stderr: at
waves.util.KeywordAdminPOA._invoke(KeywordAdminPOA.java:48)
[today] stderr: at
com.inprise.vbroker.poa.POAImpl.invoke(POAImpl.java:2088)
[today] stderr: at
com.inprise.vbroker.poa.ActivationRecord.invoke(ActivationRecord.java:94)
[today] stderr: at
com.inprise.vbroker.poa.ServerInterceptorManager$ARWrapper.invoke(ServerInte
rceptorManager.java:47)
[today] stderr: at
com.inprise.vbroker.GIOP.GiopProtocolAdapter.doRequest(GiopProtocolAdapter.j
ava:327)
[today] stderr: at
com.inprise.vbroker.GIOP.GiopProtocolAdapter.dispatchMessage(GiopProtocolAda
pter.java:431)
[today] stderr: at
com.inprise.vbroker.orb.TPDispatcherImpl$TPDispatcher.run(TPDispatcherImpl.j
ava:70)
[today] stderr: at
com.inprise.vbroker.orb.ThreadPool$PoolWorker.run(ThreadPool.java:70)


Jonathan K. Weedon

unread,
Feb 4, 2000, 3:00:00 AM2/4/00
to
Carsten,

I suspect the problem you are seeing has to do with the fact that we use
a separate class loader for each EJB Jar file. I need to do a complete
write up on this feature, and how it can lead to ClassCastExceptions. If
I am right, and you are using multiple Jar files for your EJBs, then there
are two workarounds:

1) combine your EJBs into a single Jar file.
2) set the container flag -DEJBNoClassLoader

Again, I will spend some time writing up the issues involved. For now, I
just wanted to get you on your way.

-jkw

Sesh Kumar Jalagam

unread,
Feb 4, 2000, 3:00:00 AM2/4/00
to
I had the same problem . I tried to create a SB-EB combination to generate
the primary keys and it worked every second time. I thought that it was my
mistake and didn't complain about. and since then I am using a cobra
singleton object to generate the primary keys.
I will be very glad to see if there is a solution for this problem.
thank you
sesh
Jonathan K. Weedon <jwe...@inprise.com> wrote in message
news:389AD65C...@inprise.com...

Jonathan K. Weedon

unread,
Feb 7, 2000, 3:00:00 AM2/7/00
to
Sesh,

You program seems to be running fine. I start up the
server, and then run the client multiple times:

% vbj SequenceTester
env{java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory, java.naming.corba.orb=com.inprise.vbroker.orb.ORB@59d61f85,
java.naming.factory.url.pkgs=com.inprise.j2ee.jndi:com.inprise.j2ee.jndi, java.naming.factory.object=com.inprise.j2ee.jndi.java.JavaObjectFactory}
Users :11
forums :1
% vbj SequenceTester
env{java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory, java.naming.corba.orb=com.inprise.vbroker.orb.ORB@58064b32,
java.naming.factory.url.pkgs=com.inprise.j2ee.jndi:com.inprise.j2ee.jndi, java.naming.factory.object=com.inprise.j2ee.jndi.java.JavaObjectFactory}
Users :22
forums :2
% vbj SequenceTester
env{java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory, java.naming.corba.orb=com.inprise.vbroker.orb.ORB@581d73b6,
java.naming.factory.url.pkgs=com.inprise.j2ee.jndi:com.inprise.j2ee.jndi, java.naming.factory.object=com.inprise.j2ee.jndi.java.JavaObjectFactory}
Users :33
forums :3
% vbj SequenceTester
env{java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory, java.naming.corba.orb=com.inprise.vbroker.orb.ORB@58207078,
java.naming.factory.url.pkgs=com.inprise.j2ee.jndi:com.inprise.j2ee.jndi, java.naming.factory.object=com.inprise.j2ee.jndi.java.JavaObjectFactory}
Users :44
forums :4

I wonder if you might have had two instances of the naming service running.
This can be due to the fact that you are running IAS with the naming
service, and the EJB container with its own naming service, or if you run
two instances of the EJB container each with their own instance of the
naming service. In either case, you will have multiple instances of the
naming service, where each instance is not holding all the same names.
Thus, when a client connects to the wrong one (every other time) it does
not locate the requested names.

-jkw

Carsten Jakobsen

unread,
Feb 14, 2000, 3:00:00 AM2/14/00
to
Hi Jonathan

First of all: thank you for your prompt reply.

I finally got the time to try out your workarounds, and your first
workaround (deploy in a single jar) works. I do not quite understand how the
"-DEJBNoClassLoader" also should solve my problem. I tried it and the
container does not load my EJB's anymore. The errorlog shows that:

[today] stderr: Could not deploy ejb-jar ejb_jars/ejbcontainer/ChatInfo.jar
[today] stderr: java.lang.NullPointerException
[today] stderr: at com.inprise.ejb.EJBMetaData.<init>(EJBMetaData.java:22)
[today] stderr: at com.inprise.ejb.EJBHome.<init>(EJBHome.java, Compiled
Code)

Removing the settings gets me up'n'running again.

I can use workaround no. 1 for the time being, but it is not a good
solution. Since my "Unique Key Generator" is a central bean in my system I
have to bundle all of my beans in the same JAR. Surely you will agree with
the fact that this was not the meaning of the EJB technology.

Carsten


Jonathan K. Weedon wrote in message <389AD65C...@inprise.com>...


>Carsten,
>
>I suspect the problem you are seeing has to do with the fact that we use
>a separate class loader for each EJB Jar file. I need to do a complete
>write up on this feature, and how it can lead to ClassCastExceptions. If
>I am right, and you are using multiple Jar files for your EJBs, then there
>are two workarounds:
>
>1) combine your EJBs into a single Jar file.
>2) set the container flag -DEJBNoClassLoader
>
>Again, I will spend some time writing up the issues involved. For now, I
>just wanted to get you on your way.
>
>-jkw
>
>Carsten Jakobsen wrote:
>>
>> I'm having a lot of trouble "calling" one Session Bean (or Entity Bean
for
>> that matter) from another Session Bean. I keep getting
ClassCastExceptions
>> when I do a myBean = BeanHome.create(). The calling SB does a normal jndi

>> lookup as if it was a normal client.

Jonathan K. Weedon

unread,
Feb 14, 2000, 3:00:00 AM2/14/00
to
Carsten,

I neglected to mention that if you set the flag:

-DEJBNoClassLoader

you will also have to put the EJB code into your server's
classpath, explicitly.

I agree, requiring that all cooperating EJB go into a single
Jar is not ideal. We are looking into improving this feature,
to support having a collection of Jar files loaded by a single
class loader.

-jkw

0 new messages