Question

i have created entity class from database then i have created session beans from entity class and and when i am trying to test that my data reach the entity class i have created a junit test on the session beans class but i got lookup fail "Root exception is javax.naming.NameNotFoundException: EmpTableFacade!Beans.EmpTableFacade not found even if i used EJB injection then i tried to test my code manually by creating class that use the session beans but the same exception here .

i think that the error from Deploying staff but i don't know where i did it wrong this is session beans interface .

 /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

    package Beans;

    import java.util.List;
    import javax.ejb.Local;

    /**
     *
     * @author HADDAD
     */
    @Local
    public interface EmpTableFacadeLocal {

        void create(EmpTable empTable);

        void edit(EmpTable empTable);

        void remove(EmpTable empTable);

        EmpTable find(Object id);

        List<EmpTable> findAll();

        List<EmpTable> findRange(int[] range);

        int count();

    }



 and this is the test class

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

    package Controller;

    import Beans.EmpTable;
    import Beans.EmpTableFacade;
    import java.util.List;
    import java.util.Properties;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;

    /**
     *
     * @author HADDAD
     */
    public class Functionality {
        List<EmpTable> l;
        Context c=null;
        {
            try {
                Properties props = new Properties();
                props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");

                props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
                // glassfish default port value will be 3700,
                props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
                //props.load(new  FileInputStream("jndi.properties"));
                c = new InitialContext(props);
            } catch (NamingException ex) {
                Logger.getLogger(Functionality.class.getName()).log(Level.SEVERE, null, ex);
            }
            }
        public void retrive() throws NamingException
        {


            EmpTableFacade empTableFacade=(EmpTableFacade)
                    c.lookup("java:global/employee/employee-ejb/EmpTableFacade!Beans.EmpTableFacade");
           l= empTableFacade.findAll();
           System.out.println(l.get(0).getName().toString());
        }
        public static void main(String[] args) throws NamingException
        {
            Functionality f=new Functionality();
            f.retrive();

        }
    }

and this is the exception

Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/employee/employee-ejb/EmpTableFacade!Beans.EmpTableFacade' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NameNotFoundException: EmpTableFacade!Beans.EmpTableFacade not found]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at Controller.Functionality.retrive(Functionality.java:45)
    at Controller.Functionality.main(Functionality.java:52)
Était-ce utile?

La solution

You need to expose your bean with a Remote interface. A Local interface is available only for invocation within the same JVM, which it is not your case.

The JNDI name also looks wrong. You don´t specify which ejb or server version you are using which is important to solve this kind of problem, but I think this link can help you define the correct JNDI name entry.

Also take in mind that according to glassfish doc.

Each portable global JNDI name is printed out to the server.log during deployment.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top