PDA

View Full Version : ClassCastException with SimpleRemoteStatelessSessionProxyFac



gen0
Sep 18th, 2005, 11:52 PM
Strange problem...

I have a SessionBean facade that returns a Collection of Objects which I am using from within a Web Application. When I get an instance of my SessionBean using the "old fashioned" approach, I have no problems, eg:
Context context = new InitialContext();
Object lookup = context.lookup(JNDI_NAME);
Object objHome = PortableRemoteObject.narrow(lookup,
IBroadcastServiceFacadeHome.class);
IBroadcastServiceFacadeHome home =
(IBroadcastServiceFacadeHome) objHome;
this.broadcastServiceFacade = home.create();


However... When I inject a session bean using the following snippet from my context XML:
<bean id="broadcastService"
class="org.springframework.ejb.access.SimpleRemoteStatele ssSessionProxyFactoryBean">
<property name="jndiName">
<value>java:comp/env/ejb/BroadcastService</value>
</property>
<property name="resourceRef">
<value>true</value>
</property>
<property name="businessInterface">
<value>com.gen.broadcast.IBroadcastServiceFacade</value>
</property>
</bean>


... things start to fall apart. I get the sessionbean object ok, I can call the method on it that returns a Collection, however as soon as I try to cast an Object in that Collection as one of my domain classes, I get a ClassCastException. Logging getClass().getName() tells me the Object is of the correct type, so I'm guessing some kind of class loader issue... But can anyone guess what this would be?

Andreas Senft
Sep 19th, 2005, 01:16 AM
It seems that the spring jar used by your web application is not the same as the spring jar used by the EJB. Since the classes are loaded through spring, it does matter which classloader is used to load the spring classes.
Maybe you could manage to have only one pring.jar so that classloading issues would disappear.


Regards,
Andreas

gen0
Sep 22nd, 2005, 04:40 AM
Thanks for your feedback. The spring jar looks to be the same. Ended up just going with the "old fashioned" JNDI lookup in a BusinessDelegate class, as I've got to meet my deadline. If I get the chance to discover any more I'll post it...

damiansutton
Oct 17th, 2005, 12:51 AM
Hey Guys,

I seem to have the same problem, but only since upgrading my Jboss to 4.03.

In my case I know that I am using the same Spring.jar because I have placed my spring.jar into the default/lib directory so that all my web apps/ejbs access the same spring.jar.

For my example from an ActionSupport class:


service = &#40;Service&#41; this.getWebApplicationContext&#40;&#41;.getBean&#40;"service"&#41;;

System.out.println&#40;service.test&#40;&#41;&#41;;

With a bean definition:


<bean id="service"
class="org.springframework.ejb.access.LocalStatelessSessi onProxyFactoryBean">
<property name="jndiName">
<value>ServiceLocal</value>
</property>
<property name="resourceRef">
<value>false</value>
</property>
<property name="businessInterface">
<value>Service</value>
</property>
</bean>


If service.test() returns void then I have no problems, but if it returns any type of object it throws a ClassCastException inside the proxy i.e. (before actually return but after all session bean has returned).

Please, any ideas.

Damian

Andreas Senft
Oct 17th, 2005, 04:09 AM
If you found a problem within the spring proxy, maybe this could be an issue for JIRA. Please check if an according issue already exists and open a new one if not.

Regards,
Andreas

damiansutton
Oct 17th, 2005, 07:59 AM
Thanks Andreas,

I didn't find anything under JIRA.

And I'm not quite ready to say that this a bug.

But still interested if anyone has any other ideas as to why I would be getting this problem.

Thanks,

Damian

Andreas Senft
Oct 17th, 2005, 08:21 AM
Maybe you could post the stacktrace to provide additional details.

Regards,
Andreas

damiansutton
Oct 18th, 2005, 06:50 AM
Hey Guys,

As a follow up to this issue. This was not a Spring problem at all. In fact it was due to both my ejb jar and war both having a separate copy of the same class (even though they were identical).

Obviously this was the cause of the ClassCastException.

Strange that the same code works on JBoss 4.0.1 but not 4.0.3, but that is no fault of Spring.

Damian

irbouho
Oct 25th, 2005, 10:06 PM
I experienced this same error in the past after migrating from Jboss 4.0.1 to Jboss 4.0.3. many other users experienced this same error http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3900678#3900678
The solution, as pointed out by Damian in this thread, is to make sure no client class is duplicated in EJB and WAR modules.