Class cast exception on stateful ejb

458 views Asked by At

For some strange reason I am getting the following exception.

2011-02-08 09:53:30,667 ERROR [STDERR] (QuartzScheduler_Worker-9) java.lang.ClassCastException: org.javassist.tmp.java.lang.Object_$$_javassist_seam_7 cannot be cast to no.kommuneforlaget.fagsystem.saksapp.service.report.SystemlogListener
2011-02-08 09:53:30,668 ERROR [STDERR] (QuartzScheduler_Worker-9)       at no.kommuneforlaget.fagsystem.saksapp.jobs.ESBLogListener.checkESBEvents(ESBLogListener.java:71)
2011-02-08 09:53:30,668 ERROR [STDERR] (QuartzScheduler_Worker-9)       at no.kommuneforlaget.fagsystem.saksapp.jobs.ESBLogListener.scheduler(ESBLogListener.java:119)
2011-02-08 09:53:30,668 ERROR [STDERR] (QuartzScheduler_Worker-9)       at sun.reflect.GeneratedMethodAccessor466.invoke(Unknown Source)
2011-02-08 09:53:30,668 ERROR [STDERR] (QuartzScheduler_Worker-9)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
2

I know it shouldn't be a class cast exception because its the correct class.

The code is:

SystemlogListener systemlogListener = (SystemlogListener) Component.getInstance("systemlogListener", ScopeType.SESSION, true);

And the class is

@Name("systemlogListener")
@Scope(ScopeType.SESSION)
@AutoCreate
@Stateful
@TransactionManagement(TransactionManagementType.CONTAINER) //default
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class SystemlogListener implements SystemlogListenerLocal, Serializable {

Can anyone spot the mistake I have made?

1

There are 1 answers

3
cornz On BEST ANSWER

I assume that Component.getInstance(...) returning an injected class. The Implementation that is injected does not have to be of the class of your implementation but only of your Local/Remote interface. So you could cast to your interface SystemlogListenerLocal but not to your implementation SystemlogListener.

The reason is the implementation of your AppServer which could use e.g. a proxy and delegates the methods to your real implementation.