Announcement Announcement Module
Collapse
No announcement yet.
ClassCastException with SimpleRemoteStatelessSessionProxyFac Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClassCastException with SimpleRemoteStatelessSessionProxyFac

    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.SimpleRemote StatelessSessionProxyFactoryBean">
    <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?

  • #2
    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

    Comment


    • #3
      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...

      Comment


      • #4
        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:

        Code:
        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:

        Code:
        	<bean id="service"
        	      class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
        	   <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

        Comment


        • #5
          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

          Comment


          • #6
            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

            Comment


            • #7
              Maybe you could post the stacktrace to provide additional details.

              Regards,
              Andreas

              Comment


              • #8
                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

                Comment


                • #9
                  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?modu...900678#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.

                  Comment

                  Working...
                  X