Skip to Content
0
Former Member
Jul 12, 2006 at 07:46 AM

EJBLocalHome throws ClassCastException after restart Web AS

22 Views

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?