Results 1 to 9 of 9

Thread: ClassCastException with SimpleRemoteStatelessSessionProxyFac

  1. #1
    Join Date
    Sep 2005
    Posts
    2

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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

  3. #3
    Join Date
    Sep 2005
    Posts
    2

    Default

    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...

  4. #4

    Default

    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

  5. #5
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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

  6. #6

    Default

    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

  7. #7
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Maybe you could post the stacktrace to provide additional details.

    Regards,
    Andreas

  8. #8

    Default

    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

  9. #9
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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#390067 8
    The solution, as pointed out by Damian in this thread, is to make sure no client class is duplicated in EJB and WAR modules.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

Similar Threads

  1. Replies: 11
    Last Post: Nov 28th, 2007, 12:27 PM
  2. ClassCastException and web/ejb classloading
    By jasonmcdermott in forum EJB
    Replies: 1
    Last Post: Sep 1st, 2005, 09:02 PM
  3. Submitting Form gives ClassCastException
    By curtney in forum Web Flow
    Replies: 9
    Last Post: Jul 7th, 2005, 08:32 PM
  4. ClassCastException on Hibernate saving
    By sebastien in forum Data
    Replies: 2
    Last Post: Apr 27th, 2005, 10:15 AM
  5. Replies: 1
    Last Post: Feb 4th, 2005, 12:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •