wood burning stoves 2.0*
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

Win a copy of Spring in Action this week in the Spring forum!
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 java.io.Serializable{
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="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<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(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:589)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at Client.main(Client.java:15)

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: 10202

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: 10202

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: http://aspose.com/file-tools
subject: TestEJB not bound