<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Problems using the @RemoteHome annotation for backward compatibility
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/mikemil">Mike Miller</a> in <i>EJB3</i> - <a href="https://community.jboss.org/message/799738#799738">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>We are (hopefully) coming to the end of our migration from EJB 2.1 to EJB 3 "exercise".&#160;&#160; We are encountering ClassCastExceptions when we try to load an EJB3 bean from one of our older, yet to be migrated EJB2.1 server instances.&#160;&#160; If I understood the 3.0 spec correctly, 3.0 can be a 'client' of 2.1 but not really vise versa.&#160;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Little bit of history - our product is a POS where we have a 'store server' at each retail store and a 'Central' server at company headquarters.&#160;&#160; This can NOT be big banged over night, so our migration/upgrade path means that Central will be upgraded to 3.0 first, then sets of stores will be upgraded, but not all at once. Most of the communication between servers is done thru JMS, but we do have some cases where we make what we call a 'reverse service call' which means a store loads an EJB from the Central Server's JNDI, or Central loads an EJB from the Store servers JNDI.&#160; This is where we are at right now.&#160; Central at 3.0 and Store at 2.1, then Store requests an EJB from Central and when we attempt to PortableNarrow - we get a ClassCastException.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We are doing this on JBoss 4.2.3.GA.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>If I understand the documentation correctly, it sounds like we should be able to use the @RemoteHome to generate the home interface for the 2.1 clients to use to talk to our Central Server. I have tried this and assume that I am missing some piece of the puzzle.&#160; I have tried to compare mine agains the ejb21_client_adaptors sample in the EJB3 tutorial files but it's not working.&#160;&#160; The exception we get on the Store server side is below:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>{code}</p><p>2013-02-26 13:33:00,985 ERROR [root] java.lang.RuntimeException: problem connecting to EJB container</p><p>&#160; at com.jda.portfolio.infrastructure.base.service.ServiceFactory.getRemoteService(ServiceFactory.java:503)</p><p>&#160; at com.jda.portfolio.infrastructure.base.service.ServiceFactory$CentralServerLookupThread.run(ServiceFactory.java:621)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>2013-02-26 13:33:00,989 ERROR [root] Caused by: null</p><p>java.lang.ClassCastException</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:245)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:153)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at com.jda.portfolio.infrastructure.base.service.ServiceFactory.getRemoteService(ServiceFactory.java:488)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at com.jda.portfolio.infrastructure.base.service.ServiceFactory$CentralServerLookupThread.run(ServiceFactory.java:621)</p><p>Caused by: java.lang.ClassCastException: $Proxy1238 cannot be cast to org.omg.CORBA.Object</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:228)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;... 3 more</p><p>2013-02-26 13:33:00,991 ERROR [root] Root cause: $Proxy1238 cannot be cast to org.omg.CORBA.Object</p><p>java.lang.ClassCastException: $Proxy1238 cannot be cast to org.omg.CORBA.Object</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:228)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:153)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at com.jda.portfolio.infrastructure.base.service.ServiceFactory.getRemoteService(ServiceFactory.java:488)</p><p>{code}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Below are snippets from our classes</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>EJB3 Session Bean</strong></p><p>{code}</p><p>package com.jda.portfolio.pos.server.service.security;</p><p> <span style="font-size: 10pt;">...</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><span style="font-size: 10pt;"> </span>&#160;</p><p>@Stateless</p><p>@RemoteHome(KeyManagementServiceHome.class)</p><p>@RemoteBinding(jndiBinding="ejb/KeyManagementService")</p><p>@LocalBinding(jndiBinding="ejb/KeyManagementServiceLocal")</p><p>@TransactionManagement(TransactionManagementType.CONTAINER)</p><p>@TransactionAttribute(TransactionAttributeType.REQUIRED)</p><p>public class KeyManagementServiceBean extends com.jda.portfolio.infrastructure.server.service.AbstractService implements KeyManagementService, KeyManagementServiceLocal</p><p>{</p><p>&#160;&#160;&#160; @Init</p><p>&#160;&#160;&#160; public void ejbCreate()&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("**** ejbCreate() of " + this.getClass() + " called ****");</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>...</p><p>}</p><p>{code}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>New Home interface for 2.1 clients</strong></p><p>{code}</p><p>package com.jda.portfolio.pos.server.service.security;</p><p>...</p><p>public interface KeyManagementServiceHome extends EJBHome {</p><p>&#160; </p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;public KeyManagementServiceRemote create() throws CreateException, RemoteException;</p><p>}</p><p>{code}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>Remote interface created by Home</strong></p><p>{code}</p><p>package com.jda.portfolio.pos.server.service.security;</p><p> import javax.ejb.EJBObject;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> public interface KeyManagementServiceRemote extends EJBObject {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160; public int addKey( com.jda.portfolio.infrastructure.base.util.KeyGenData keyGenData ) ;</p><p>&#160;&#160;&#160; public boolean publishKeys( java.util.List locationNumbers ) ;</p><p> <span style="font-size: 10pt;">&#160; public int removeKeys( java.util.List keysToRemove ) ;</span></p><p>&#160; }</p><p>{code}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Using no deployment descriptors.&#160; After making this change, I did dump the JNDIView for my Central (3.0) server from the console and noticed one strange entry that does not show up in our other servers.&#160; There is an entry that looks like a subcontext of "KeyManagementServiceBean" with a named pair of 'home' : $Proxy1256.&#160;&#160; The KeyManagementServiceBean is actually the name of the class for the EJB Session bean I am trying to make available as a 2.1 bean.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Setting breakpoints in the Store server where we are loading and attempting to narrow the reference - I also noticed that the class within the proxy class is usually 'ClientContainer' when things work, like for 2.1 - but when we load the 3.0 bean from Central, the class name in the proxy is StatelessRemoteProxy.&#160; Not sure if that means anything or just a result of the different implementations.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I know there's a lot of info here but I can help clarify it if it is not clear.&#160;&#160; </p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/799738#799738">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>