JDeveloper multi-project app problems...

Discussions

EJB programming & troubleshooting: JDeveloper multi-project app problems...

  1. multi-project application issues (please help)...

    I am developing an EJB app that consist of two projects: One for entity beans and one for session beans. I have already developed the entity bean project which I have tested using the sample clients created by JDev's wizards.

    Now I am developing the session beans project but I am having trouble to get the beans instantiated. For example, in the session beans implementation class I have:

    public ebUsuario loginUsuario(String user) throws RemoteException
    {
    try
    {
    Context ctx = new InitialContext();
    Object obj = ctx.lookup("ejb/ebUser");
    EbUserHome = (ebUserHome) PortableRemoteObject.narrow(obj,ebUserHome.class);
    EbUser = EbUserHome.findByUser(user);
    .
    .
    .

    }
    catch (Exception e)
    {
    System.err.println("Couldn't get the user!");
    e.printStackTrace();
    throw new RemoteException(e.getMessage());
    }
    }

    with a deployment descriptor (ejb-jar.xml) that includes:

    <session>
    <description>Session Bean ( Stateless )</description>
    <display-name>sbUser</display-name>
    <ejb-name>sbUser</ejb-name>
    <home>controlBeansPkg.sbUserHome</home>
    <remote>controlBeansPkg.sbUser</remote>
    <ejb-class>controlBeansPkg.impl.sbUserBean</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    <ejb-ref>
    <ejb-ref-name>ejb/ebUser</ejb-ref-name>
    <ejb-ref-type>Entity</ejb-ref-type>
    <home>dataBeansPkg.ebUserHome</home>
    <remote>dataBeansPkg.ebUser</remote>
    <ejb-link>ebUser</ejb-link>
    </ejb-ref>
    </session>

    My client looks like:

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "welcome");
    env.put(Context.PROVIDER_URL, "ormi://localhost:23891/current-workspace-app");
    Context ctx = new InitialContext(env);
    sbUsuarioHome SbUsuarioHome = (sbUsuarioHome)ctx.lookup("sbUser");
    sbUser SbUser = SbUserHome.create( );
    ebUser EbUser = SbUser.loginUsuario( "Fedro" );

    The problem is that whenever I run the app (embeded OC4J) I get an error like:

    ---->

    SamplecontrolBeansPkg.sbUserClient
    javax.naming.NamingException: Disconnected: Unknown command: 7

    java.lang.Object com.evermind.server.rmi.RMIContext.lookup(java.lang.String)

    java.lang.Object javax.naming.InitialContext.lookup(java.lang.String)

    void SamplecontrolBeansPkg.sbUserClient.main(java.lang.String[])

    Process exited with exit code 0.

    And when I try to deploy to a remote 9iAS Server the entity beans project gets correctly deployed but for the session beans project I get:

    Auto-deploying controlBeans (New server version detected)...
    Copying default deployment descriptor from archive at C:\Oracle\iSuites\j2ee\home\applications\controlBeans/controlBeans.jar/META-INF/orion-ejb-jar.xml to deployment directory C:\Oracle\iSuites\j2ee\home\application-deployments\controlBeans\controlBeans.jar...
    java.lang.NoClassDefFoundError: dataBeansPkg/ebUser

    I have alredy set up a library entry in the session's beans project properties named dataBeans whose class path points to:
    C:\Oracle\iSetup\jdev\mywork\MesaEventos\dataBeans\classes
    which is the Output directory of the entity beans project. Code insight is working OK, so the methods of the entity beans are displayed while coding.
    Is there something else I should set up in order for one project to access beans in another project?
    I'm really clueless on this issue, please help...
  2. Looks like you got yourself into a nice complex bind here. I could be off but I believe your problem is that your ejb's in seperate jars are not seeing each other, a.k.a. a J2EE classloader issue. What version of J2EE are you using in oracle AS? First thing I would try is to package the entities and sessions into the same jar and then deploy. See if that works in Oracles AS? If so then I believe that is your problem and you should read up on:

    https://www.theserverside.com/resources/articles/ClassLoading/article.html
    and
    http://www.onjava.com/lpt/a/onjava/2001/06/26/ejb.html

    If your using 1.3 then you should be able to use the ejb extension architecture where you can define dependant beans in a jars manifest.

    Again, I'm only guessing as to what the problem is and the possible solution...hope this helps.
  3. Well, I managed to run the project inside the Embeded OC4J runtime. By placing part of the code in the ejbCreate Method, and making both EbUser and EbUserHome global private members of the session EJB:

    ejbCreate(...
    try
    {
    Context ctx = new InitialContext();
    Object obj = ctx.lookup("ejb/ebUser");
    EbUserHome = (ebUserHome) PortableRemoteObject.narrow(obj,ebUserHome.class);
    .
    .
    .

    }
    catch (Exception e)
    {
    System.err.println("Couldn't get the Home Interface!");
    e.printStackTrace();
    throw new RemoteException(e.getMessage());
    }
    }

    Then I modified the loginUsuario as follows...

    public ebUsuario loginUsuario(String user) throws RemoteException
    {
    try
    {
    EbUser = EbUserHome.findByUser(user);
    .
    .
    .

    }
    catch (Exception e)
    {
    System.err.println("Couldn't get the user!");
    e.printStackTrace();
    throw new RemoteException(e.getMessage());
    }
    }

    the rest of the code was not touched...

    The end result: The project runs inside the embeded OC4J instance. It deploys correctly to the remote 9iAS but whenever I run a remote client I get an error stating that ejb/ebUser was not found.

    Any clues?

    I am running OC4J 9.0.2. and JDeveloper 9.0.2 also.