javaglassfishglassfish-4.1

JAVA Lookup Failed for bean name in SerialContext


The Scenario goes as follows :

i'm coding a java enterprise application

first i created entity classes from database table "Derby" then i made a helper classes in a java library project then i created a session bean in the enterprise application bean and created a bean facade remote in the java library project

here is the important code part of the session bean :

@Stateless(mappedName = "officefacade")
public class OfficeFacade implements OwnerFacadeRemote {
        @PersistenceContext
        private EntityManager em;

and then i coded a simple client to test the methods

client code :

public class Client {

private OwnerFacadeRemote request;
public static void main(String[] args) {
    // TODO code application logic here
    Client x = new Client();

}

public Object getEJBBean(String beanName)
{
        try
        {
            InitialContext ctx = new InitialContext();
            return ctx.lookup(beanName);
        }
        catch(Exception ex)
        {
            System.err.println("Error : " + ex.getMessage() + "\n\n\n");
        }
        return null;
 }

private void insert()
{
    request.createOwner(new OwnerDetails("1","M","444","M","afcdv"));
}

private void display()
{
    List<OwnerDetails> xx = request.getAllOwner();

}

public Client() 
{
    request = (OwnerFacadeRemote) getEJBBean("officefacade");

    insert();
    display();
}

the problem is every time i run the client i get the error that Lookup failed for 'officefacade'

here is the complete error text

> Error : Lookup failed for 'officefacade' in SerialContext[myEnv{java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFac   tory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}

how to make sure the mapped name is being available and how to fix it so the it can be found by the lookup even if it means hard coding the mapped name in the serial context "i don't know what this is but it seem as the problem is coming from it"

any help is much appreciated and thanks in advance for your efforts and i'm pretty sure everything is implemented correctly so it's a mapped name related problem

tools of development is netbeans 8.0.2 and glassfish 4.1


Solution

  • Try to replace @Stateless(mappedName = "officefacade") with @Stateless(name = "officefacade"), the lookup method of the InitialContext seems to work with the bean name

    See the related JavaDoc section and the related method for more details

    UPDATE

    Just checked Oracle's documentation on this topic - according to the information available there you might need to actually lookup for "java:module/officefacade" instead of pure "officefacade", depending on the bean context.