• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

cannot find my entity bean

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
although in my deployment descriptors under weblogic ejb jar/weblogic enterprise bean/PersonBean/ the JNDI name is set correctly to PersonHome, the client sends the following error:
C:\stage\entity>java PersonClient
Unable to lookup the Person EJB.
Please make sure that the bean has been deployed, and the client's classpath has been set correctly.
Exception in thread "main" javax.naming.NameNotFoundException: Unable to resolve 'PersonHome' Resolved: '' Unresolved:'P
ersonHome' ; remaining name 'PersonHome'
at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:85)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:262)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:229)
at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)
at $Proxy0.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:341)
at javax.naming.InitialContext.lookup(InitialContext.java:345)
at PersonClient.runClient(PersonClient.java:63)
at PersonClient.main(PersonClient.java:110)
here is my weblogic-ejb-jar.xml:
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>PersonBean2</ejb-name>
<entity-descriptor>
<persistence>
<persistence-type>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>6.0</type-version>
<type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
</persistence-type>
<persistence-use>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>6.0</type-version>
</persistence-use>
</persistence>
</entity-descriptor>
<jndi-name>PersonHome</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

My client application looks like:
try {
Date d1 = new Date();
ctx = getInitialContext();
Date d2 = new Date();
Object h = ctx.lookup("PersonHome");
Date d3 = new Date();
home = (PersonHome)
PortableRemoteObject.narrow(h, PersonHome.class);

System.out.println("time for creating InitialContext in milli sec : "+ (d2.getTime()-d1.getTime()) );
System.out.println("time for JNDI lookup in milli sec : "+ (d3.getTime()-d2.getTime()) );
} catch (NamingException ne) {
System.err.println("Unable to lookup the Person EJB.");
System.err.println("Please make sure that the bean has been deployed"+
", and the client's classpath has been set correctly.");
throw ne;
}

Any idea what is wrong ?
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to specify the correct properties when you retrieve the InitialContext in your client. Try the following code:

This is assuming that your client is executing on the same machine as your WebLogic instance and that you are using the default Listen Port. Furthermore, you can avoid the ugly property stuff by specifying these values in a jndi.properties file on your CLASSPATH.
Let me know how it goes and write.
Last thing, take a quick look at the naming policy and edit your profile accordingly.
 
Maximilian Trenks
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well sorry seems I forgot to paste it ...
of course my code includes what you have posted
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Three Questions:
  • Does your EJB compile correctly using ejbc?
  • Have you confirmed that your EJB is being properly deployed in the WebLogic?
  • Have you checked WebLogic's JNDI tree to confirm that your EJB, is in fact, bound to the correct JNDI name?

  • [ February 22, 2003: Message edited by: Chris Mathews ]
     
    Maximilian Trenks
    Ranch Hand
    Posts: 104
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    mom I try something (posting an image):

    as you can see, the bean is deployed, the jndi name is set correct.
    the full client code looks like the following:
    ************************************************
    import java.util.Properties;
    import java.util.Date;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.rmi.PortableRemoteObject;
    public class PersonClient {
    private Context ctx;

    private String url = "t3://localhost:7001";

    protected Context getInitialContext()
    throws NamingException
    {
    if (ctx == null) {
    try {
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    p.put(Context.PROVIDER_URL, url);
    p.put(Context.SECURITY_PRINCIPAL, "system");
    p.put(Context.SECURITY_CREDENTIALS, "sichernicht");
    ctx = new InitialContext(p);
    } catch (NamingException ne) {
    System.err.println("** Unable to connect to the server at:");
    ne.printStackTrace();
    throw ne;
    }
    }
    return ctx;
    }
    PersonClient(String [] argv)
    throws NamingException
    {
    //ctx = new InitialContext();
    //ctx = getInitialContext();
    }


    public void runClient()
    throws Exception
    {

    PersonHome home = null;
    try {
    Date d1 = new Date();
    ctx = getInitialContext();
    Date d2 = new Date();
    Object h = ctx.lookup("PersonHome");
    Date d3 = new Date();
    home = (PersonHome)
    PortableRemoteObject.narrow(h, PersonHome.class);

    System.out.println("time for creating InitialContext in milli sec : "+ (d2.getTime()-d1.getTime()) );
    System.out.println("time for JNDI lookup in milli sec : "+ (d3.getTime()-d2.getTime()) );
    } catch (NamingException ne) {
    System.err.println("Unable to lookup the Person EJB.");
    System.err.println("Please make sure that the bean has been deployed"+
    ", and the client's classpath has been set correctly.");
    throw ne;
    }
    try {
    String name = new String("Max");
    String id = new String("123");
    Date d1 = new Date();
    Person p = home.findByPrimaryKey(id);
    Date d2 = new Date();
    System.out.println("Time for finding a single entry: "+ (d2.getTime()-d1.getTime()));
    java.util.Collection c = home.findByName(name);
    Date d3 = new Date();
    System.out.println("Time for finding a collection of entries: "+ (d3.getTime()-d2.getTime()));
    System.out.println(c.size()+" entries found for "+name);
    Date d4 = new Date();
    p.remove();
    Date d5 = new Date();
    System.out.println("Time for deleting an entry: "+ (d5.getTime()-d4.getTime()));
    p = home.create(id,name);
    Date d6 = new Date();
    System.out.println("Time for creating a new entry: "+ (d6.getTime()-d5.getTime()));

    } catch (Exception e) {
    System.err.println("Received an unexpected exception " + e
    + " while using the PersonEJB.");
    throw e;
    }
    }
    public static void main(String[] argv)
    throws Exception
    {
    PersonClient c = new PersonClient(argv);
    c.runClient();
    }
    }
    **********************************************
    I already had this bean running, but I had to recompile it for adding a finder method and since then I could redeploy it but no run it.
    Is there any possibility to see all possible jndi references in the tree ?
     
    Chris Mathews
    Ranch Hand
    Posts: 2713
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This just tells me what is in the deployment descriptor. It does not tell me:
  • If the EJB has properly deployed without errors.
  • What is bound to the JNDI tree.


  • To check if the EJB has been properly deployed, open up the weblogic log and check for errors.
    To see what is bound currently to the JNDI tree:
    Goto your server
    Right-click and select View JNDI Tree
    I am running under the assumption that you have already tried restarting WebLogic, if not then restart now. Hot deployment of EJBs is very touchy... it usually works fine if you haven't changed the interfaces. Even then it sometimes flips out. However, if you do change the interfaces then you MUST restart to redeploy the EJB.
     
    Maximilian Trenks
    Ranch Hand
    Posts: 104
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    many thanx for helping me !
    I really found an error in the log and it seems the bean got deployed with the error.
    but it is not over yet :-)
    I ran my client and got the following error:
    C:\stage\entity>java PersonClient
    time for creating InitialContext in milli sec : 1172
    time for JNDI lookup in milli sec : 140
    Received an unexpected exception javax.ejb.ObjectNotFoundException: Bean with primary key '123' was not found by 'findBy
    PrimaryKey'.
    Start server side stack trace:
    javax.ejb.ObjectNotFoundException: Bean with primary key '123' was not found by 'findByPrimaryKey'.
    at PersonBean2_k3evwt__WebLogic_CMP_RDBMS.ejbFindByPrimaryKey(PersonBean2_k3evwt__WebLogic_CMP_RDBMS.java:453)
    at java.lang.reflect.Method.invoke(Native Method)
    at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.findByPrimaryKey(RDBMSPersistenceManager.java:167)
    at weblogic.ejb20.manager.BaseEntityManager.findByPrimaryKey(BaseEntityManager.java:430)
    at weblogic.ejb20.manager.BaseEntityManager.remoteFindByPrimaryKey(BaseEntityManager.java:377)
    at weblogic.ejb20.internal.EntityEJBHome.findByPrimaryKey(EntityEJBHome.java:332)
    at PersonBean_k3evwt_HomeImpl.findByPrimaryKey(PersonBean_k3evwt_HomeImpl.java:138)
    at PersonBean_k3evwt_HomeImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
    at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    End server side stack trace
    while using the PersonEJB.
    Exception in thread "main" javax.ejb.ObjectNotFoundException: Bean with primary key '123' was not found by 'findByPrimar
    yKey'.
    Start server side stack trace:
    javax.ejb.ObjectNotFoundException: Bean with primary key '123' was not found by 'findByPrimaryKey'.
    at PersonBean2_k3evwt__WebLogic_CMP_RDBMS.ejbFindByPrimaryKey(PersonBean2_k3evwt__WebLogic_CMP_RDBMS.java:453)
    at java.lang.reflect.Method.invoke(Native Method)
    at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.findByPrimaryKey(RDBMSPersistenceManager.java:167)
    at weblogic.ejb20.manager.BaseEntityManager.findByPrimaryKey(BaseEntityManager.java:430)
    at weblogic.ejb20.manager.BaseEntityManager.remoteFindByPrimaryKey(BaseEntityManager.java:377)
    at weblogic.ejb20.internal.EntityEJBHome.findByPrimaryKey(EntityEJBHome.java:332)
    at PersonBean_k3evwt_HomeImpl.findByPrimaryKey(PersonBean_k3evwt_HomeImpl.java:138)
    at PersonBean_k3evwt_HomeImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
    at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    End server side stack trace
    at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:85)
    at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:262)
    at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:229)
    at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)
    at $Proxy1.findByPrimaryKey(Unknown Source)
    at PersonClient.runClient(PersonClient.java:82)
    at PersonClient.main(PersonClient.java:110)
    C:\stage\entity>

    I checked my deployment descriptors, they were ok. Also in the database the entity with the primary key '123' did exist.
    Can you help me again please ?
     
    Maximilian Trenks
    Ranch Hand
    Posts: 104
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I found out that the
    java.util.Collection c = home.findByName(name);
    method was working properly.
    all entires were found, only the methods involving my primary key (string) didn't work.
    strange, isn't it ?
     
    Chris Mathews
    Ranch Hand
    Posts: 2713
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hmm... I am assuming that this worked previously. However, I can't really help without more details...
    Open a new thread and we will start on this problem. The first thing that I would like to see is the actual Java code for your EJB, along with the ejb-jar.xml contents.
    [ February 22, 2003: Message edited by: Chris Mathews ]
    [ February 23, 2003: Message edited by: Chris Mathews ]
     
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Just two thought
    1. Try 127.0.0.1 instead of localhost
    2. It's always good to isolate down to the individual line the client is failing on. Try inserting a state variable - in the example below it's a String called action:
    public void runClient()
    throws Exception
    {
    String action="Starting";
    PersonHome home = null;
    try {
    Date d1 = new Date();
    action="getting context";
    ctx = getInitialContext();
    Date d2 = new Date();
    action="doing lookup";
    Object h = ctx.lookup("PersonHome");
    Date d3 = new Date();
    action="doing narrow";
    home = (PersonHome)
    PortableRemoteObject.narrow(h, PersonHome.class);
    System.out.println("time for creating InitialContext in milli sec : "+ (d2.getTime()-d1.getTime()) );
    System.out.println("time for JNDI lookup in milli sec : "+ (d3.getTime()-d2.getTime()) );
    } catch (NamingException ne) {
    System.err.println("Unable to lookup the Person EJB.");
    System.err.println("Please make sure that the bean has been deployed"+
    ", and the client's classpath has been set correctly.");
    // Something like
    System.err.println(
    "Exception:"+ne+" while "+action);
    throw ne;
    }
     
    Trust God, but always tether your camel... to this tiny ad.
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic