cancel
Showing results for 
Search instead for 
Did you mean: 

EJBLocalHome throws ClassCastException after restart Web AS

Former Member
0 Kudos

I have a piece of code where I will retrieve a EJBLocalHome. When I

deploy my application, it works fine. But My problem will rise if I

restart my SAP Web AS. After restart, It will throw ClassCastException.

I wonder why. Following is the snippets of my code:

//Begin of code snippet

String jndiName

= "localejbs/com/mbb/crrs/business/common/SeqNoGenerator";

EJBLocalHome home = (EJBLocalHome)context.lookup(jndiName);

if (oHome instanceof EJBLocalHome)

logger.debug("home is instance of EJBLocalHome");

else

logger.debug("home is NOT instance of EJBLocalHome");

if (oHome instanceof SequenceNoGeneratorLocalHome)

logger.debug("home is instance of SequenceNoGeneratorLocalHome");

else

logger.debug("home is NOT instance of SequenceNoGeneratorLocalHome");

if (oHome instanceof SequenceNoGeneratorHome)

logger.debug("home is instance of SequenceNoGeneratorHome");

else

logger.debug("home is NOT instance of SequenceNoGeneratorHome");

SeqNoGeneratorLocalHome seqHome = (SeqNoGeneratorLocalHome)home;

//End of code snippet

I found out that after deployed the application, The output of following code are:

->home is instance of EJBLocalHome

->home is instance of SequenceNoGeneratorLocalHome

->home is NOT instance of SequenceNoGeneratorHome

It shows that everything is OK. It returns the correct EJBLocalHome of SequenceNoGeneratorLocalHome. But after I restart the Web AS, the output

will be as following:

->home is instance of EJBLocalHome

->home is NOT instance of SequenceNoGeneratorLocalHome

->home is NOT instance of SequenceNoGeneratorHome

->ClassCastException is thrown

It seems like the object returned can't be cast from EJBLocalHome to SequenceNoGeneratorLocalHome. How can this happened?

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

Hi John,

The problem is must probably with class loader. From where are you calling your EJB?

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

I'm calling it from a servlet which I deployed in SAP Web AS. Previously, this piece of code worked fine. I noticed after I applied the Support Package 17 of SAP Web AS, this began to happen.

So everytime I restart my SAP Web AS, I need to redeploy my application. This is very frustrating. Hope somebody could help.

former_member182372
Active Contributor
0 Kudos

Hi John,

Is your Web application with the servlet in the same EAR as EJB?

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Yes, the servlet is build in a Web Project and the EJB is build in a EJB Project but compiled in a same EAR project. This is an old piece of code. I noticed this problem only appears after I applied the SP17 stack for my Web AS 6.40. Is there any connection?

Former Member
0 Kudos

I've changed the code to make a remote invocation call instead of local and it works. Thanks Maksim. But I don't know why before this it works fine. Hmm..