Link to home
Start Free TrialLog in
Avatar of prem_kumar79
prem_kumar79

asked on

javax.naming.NameNotFoundException

able to deploy CMP bean to standalone OC4J (9.0.3.0.0) via JDeveloper Version 9.0.2.798. But, when I try to access bean following error is thrown.

javax.naming.NameNotFoundException: Emp not found

at com.evermind.server.rmi.RMIContext.lookup(RMIContext.java:124)

at javax.naming.InitialContext.lookup(InitialContext.java:350)

at Samplemypackage1.EmpClient.main(EmpClient.java:23)

Process exited with exit code 0.

package Samplemypackage1;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import mypackage1.Emp;
import mypackage1.EmpHome;
import java.util.Collection;
import java.util.Iterator;

public class EmpClient
{
public static void main(String [] args)
{
EmpClient empClient = new EmpClient();
try
{
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, "prem");
env.put(Context.PROVIDER_URL, "ormi://localhost:23791/Emp");
Context ctx = new InitialContext(env);
EmpHome empHome = (EmpHome)ctx.lookup("Emp");
}
catch(Throwable ex)
{
ex.printStackTrace();
}

}
}
The error occurs when it looks for the bean

EmpHome empHome = (EmpHome)ctx.lookup("Emp");

There is no problem in the deployment process it makes connection to the Pointbase database while getting deployed.

The bean files are in application directory plus application-deployments directory too.

There is no problem with Session or Sessionless bean.

Even after changing the code to

Context ctx = new com.evermind.server.rmi.RMIInitialContextFactory().getInitialContext(env);
//EmpHome empHome = (EmpHome)ctx.lookup("Emp");
Object empHome = ctx.lookup("Emp");

the error is not rectified.



The server.xml has

<application name="Emp" path="../applications/Emp.ear" auto-start="true" />

and ejb-jar.xml has

<ejb-name>Emp</ejb-name>





<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE orion-ejb-jar PUBLIC "-//Evermind//DTD Enterprise JavaBeans 1.1 runtime//EN" "http://xmlns.oracle.com/ias/dtds/orion-ejb-jar.dtd">
<orion-ejb-jar>
<enterprise-beans>
<entity-deployment name="Emp" copy-by-value="false" data-source="com.pointbase.xa.xaDataSource" exclusive-write-access="false" location="E:\forte4j\pointbase\databases\samples.dbn" table="EMP">
<primkey-mapping>
<cmp-field-mapping>
<fields>
<cmp-field-mapping name="id" persistence-name="ID" persistence-type="INTEGER(10)"/>
</fields>
</cmp-field-mapping>
</primkey-mapping>
<cmp-field-mapping name="id" persistence-name="ID" persistence-type="INTEGER(10)"/>
<cmp-field-mapping name="name" persistence-name="NAME" persistence-type="VARCHAR(20)"/>
<cmp-field-mapping name="dept" persistence-name="DEPT" persistence-type="VARCHAR(2)"/>
</entity-deployment>
</enterprise-beans>
<assembly-descriptor>
<default-method-access>
<security-role-mapping name="<default-ejb-caller-role>" impliesAll="true"/>
</default-method-access>
</assembly-descriptor>
</orion-ejb-jar>


<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd">
<ejb-jar>
<enterprise-beans>
<entity>
<description>Entity Bean ( Container-managed Persistence )</description>
<display-name>Emp</display-name>
<ejb-name>Emp</ejb-name>
<home>mypackage1.EmpHome</home>
<remote>mypackage1.Emp</remote>
<ejb-class>mypackage1.impl.EmpBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>mypackage1.EmpPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-field>
<field-name>id</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<cmp-field>
<field-name>dept</field-name>
</cmp-field>
</entity>
</enterprise-beans>
</ejb-jar>


I think JNDI is problem. Should I specify it somewhere?
I do not what is wrong with the code. Please help.
Avatar of gwang77
gwang77

JNDI name wrong, you can try "ejb/Emp".
Object empHome = ctx.lookup("ejb/Emp");
Avatar of girionis
 Try to change your lookup to: java:comp/env/ejb/Emp and see what happens.
Also, try changing this:

env.put(Context.PROVIDER_URL, "ormi://localhost:23791/Emp");

to this:

env.put(Context.PROVIDER_URL, "ormi://localhost:23791");
Avatar of prem_kumar79

ASKER

Object empHome = ctx.lookup("ejb/Emp");

java:comp/env/ejb/Emp


env.put(Context.PROVIDER_URL, "ormi://localhost:23791/Emp");

to this:

env.put(Context.PROVIDER_URL, "ormi://localhost:23791");

Did not work. Showed the same error
comment out the

env.put(Context.PROVIDER_URL, "ormi://localhost:23791");

line and run the client local to the server...

Same error?
Try using
ctx.list("ormi://localhost:23791");

to get an enumeration of all the bound objects' names (as a NamingEnumeration), then iterate through and see what's in there.

-Mark.
NamingEnumeration n= ctx.list("ormi://localhost:23791");
System.out.println(n.hasMore());

Returns “False”

The problem is only for CMP bean and not for Session or Sessionless beans.
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial