File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes TestEJB not bound Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "TestEJB not bound" Watch "TestEJB not bound" New topic

TestEJB not bound

Ranj Pillai

Joined: Dec 15, 2007
Posts: 2
My jar file name is TestEJB.jar

It has an entity class Cabin

package com.titan.domain;

import javax.persistence.*;

public class Cabin implements{
private int id;
private String name;
private int deckLevel;
private int shipId;
private int bedCount;

public int getId( ) { return id; }
public void setId(int pk) { id = pk; }

public String getName( ) { return name; }
public void setName(String str) {name = str; }

public int getDeckLevel( ) { return deckLevel; }
public void setDeckLevel(int level) { deckLevel = level; }

public int getShipId( ) { return shipId; }
public void setShipId(int sid) { shipId = sid; }

public int getBedCount( ) { return bedCount; }
public void setBedCount(int bed) { bedCount = bed; }



<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<persistence-unit name="TestEJB" transaction-type="JTA">

Then i have a session bean TravelAgentBean with a remote interface TravelAgentRemote

the remote interface is

package com.titan.travelagent;

import javax.ejb.Remote;
import com.titan.domain.Cabin;

public interface TravelAgentRemote {

public void createCabin(Cabin cabin);
public Cabin findCabin(int id);

The bean class is

package com.titan.travelagent;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import org.jboss.annotation.ejb.RemoteBinding;

import javax.persistence.PersistenceContext;

import com.titan.domain.Cabin;



public class TravelAgentBean implements TravelAgentRemote{
private EntityManager manager;

public void createCabin(Cabin cabin) {

public Cabin findCabin(int pKey) {
return manager.find(Cabin.class, pKey);

Then the client application is

import com.titan.travelagent.TravelAgentRemote;
import com.titan.domain.Cabin;

import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;

public class Client {
public static void main(String [] args)
try {

Object ref = getInitialContext().lookup("TestEJB/TravelAgentRemote");
TravelAgentRemote dao = (TravelAgentRemote)

Cabin cabin_1 = new Cabin( );
cabin_1.setName("Master Suite");


Cabin cabin_2 = dao.findCabin(1);
System.out.println(cabin_2.getName( ));
System.out.println(cabin_2.getDeckLevel( ));
System.out.println(cabin_2.getShipId( ));
System.out.println(cabin_2.getBedCount( ));

} catch (javax.naming.NamingException ne)
ne.printStackTrace( );

public static Context getInitialContext( )
throws javax.naming.NamingException {

Properties p = new Properties( );
" org.jboss.naming rg.jnp.interfaces");
p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
return new javax.naming.InitialContext(p);


I am using JBoss and geeting an exception
javax.naming.NameNotFoundException: TestEJB not bound
at org.jnp.server.NamingServer.getBinding(
at org.jnp.server.NamingServer.getBinding(
at org.jnp.server.NamingServer.getObject(
at org.jnp.server.NamingServer.lookup(
at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at sun.rmi.server.UnicastServerRef.dispatch(
at sun.rmi.transport.Transport$
at Method)
at sun.rmi.transport.Transport.serviceCall(
at sun.rmi.transport.tcp.TCPTransport.handleMessages(
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(
at sun.rmi.transport.tcp.TCPTransport$
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
at java.util.concurrent.ThreadPoolExecutor$
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(
at sun.rmi.transport.StreamRemoteCall.executeCall(
at sun.rmi.server.UnicastRef.invoke(
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(
at org.jnp.interfaces.NamingContext.lookup(
at javax.naming.InitialContext.lookup(
at Client.main(

What is the error in this please help. I need to know it urgently
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hi Ranj,

I am not quite sure if JBoss has complete EJB 3.0 support available yet. If you are just trying out a sample, you may want to use Glassfish app server.

Shailesh Kini.
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

Originally posted by Shailesh Kini:

I am not quite sure if JBoss has complete EJB 3.0 support available yet.

JBoss does have EJB3 support

[My Blog] [JavaRanch Journal]
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

As for the original question:

Object ref = getInitialContext().lookup("TestEJB/TravelAgentRemote");
TravelAgentRemote dao = (TravelAgentRemote)

Change your lookup string to "TravelAgentRemote". Also in EJB3, you no longer need the PortableRemoteObject.narrow call.

Your code should look like:

Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hi Jaikiran,

You are correct, JBoss 5.0 Beta1 has JEE support.
I agree. Here's the link:
subject: TestEJB not bound
It's not a secret anymore!