users@glassfish.java.net

Re: Java Persistence API

From: Sahoo <Sahoo_at_Sun.COM>
Date: Thu, 19 Feb 2009 22:06:54 +0530

Looks like you didn't read the FAQ properly. Can you answer the followings:
1. Why do you think jndi-name of the target EJB is TestBean?
2. Why are you doing

ic.lookup("TestBean")

when you are already trying to inject an EJB?

Please read the FAQ carefully. As per
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#SessionBeanGlobalJNDINameAssignment
, the JNDI name of the EJB is fully qualified name of the remote
business interface.

Use this name in sun-application-client.xml as the jndi-name or as
mappedName attribute in @EJB or in ic.lookup.

Sahoo

glassfish_at_javadesktop.org wrote:
> Hi,
>
> Thanks for your information. I am trying as follows,
>
> #1 I have created a sun-application-client.xml descriptor.
>
> <sun-application-client>
> <ejb-ref>
> <ejb-ref-name>ejb/Test</ejb-ref-name>
> <jndi-name>TestBean</jndi-name>
> </ejb-ref>
> </sun-application-client>
>
>
> #2 In my AppClient.java code I say,
>
> package client;
>
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import javax.ejb.*;
> import ejb.Test;
> import javax.naming.InitialContext;
> import javax.naming.NamingException;
>
> /**
> * @author NetbeansUser
> */
> public class AppClient {
>
> @EJB(name="ejb/Test")
> private static Test sb;
>
> public AppClient() throws NamingException {
> InitialContext ic = new InitialContext();
> sb = (Test) ic.lookup("TestBean");
> }
>
> public static void main(String[] args) {
> try {
> AppClient test = new AppClient();
> test.runTest();
> } catch (NamingException ex) {
> Logger.getLogger(AppClient.class.getName()).log(Level.SEVERE, null, ex);
> }
> }
>
>
> public void runTest() {
>
> // Persist all entities
> System.out.println("Inserting Customer and Orders... " + sb.testInsert());
>
> // Test query and navigation
> System.out.println("Verifying that all are inserted... " + sb.verifyInsert());
>
> // Get a detached instance
> int id = sb.findCustomer("Joe Smith");
>
> // Remove all entities
> System.out.println("Removing all... " + sb.testDelete(id));
>
> // Query the results
> System.out.println("Verifying that all are removed... " + sb.verifyDelete());
> }
> }
>
> and I get a NameNotFoundException,
>
> 19-feb-2009 16:10:51 client.AppClient main
> GRAVE: null
> javax.naming.NameNotFoundException: TestBean not found
> at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext.java:216)
> at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:188)
> at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:74)
> at com.sun.enterprise.naming.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:129)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:154)
> at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:687)
> at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:227)
> at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1846)
> at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1706)
> at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1088)
> at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:223)
> at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:806)
> at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:563)
> at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2567)
> at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
>
> What am i doing wrong?
>
> Regards,
> Jose Alvarez de Lara
> [Message sent by forum member 'josealvarezdelara' (josealvarezdelara)]
>
> http://forums.java.net/jive/thread.jspa?messageID=332929
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>