• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TestEJB not bound

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My jar file name is TestEJB.jar

It has an entity class Cabin

package com.titan.domain;

import javax.persistence.*;

@Entity
@Table(name="CABIN")
public class Cabin implements java.io.Serializable{
private int id;
private String name;
private int deckLevel;
private int shipId;
private int bedCount;

@Id
@Column(name="ID")
public int getId( ) { return id; }
public void setId(int pk) { id = pk; }

@Column(name="NAME")
public String getName( ) { return name; }
public void setName(String str) {name = str; }

@Column(name="DECK_LEVEL")
public int getDeckLevel( ) { return deckLevel; }
public void setDeckLevel(int level) { deckLevel = level; }

@Column(name="SHIP_ID")
public int getShipId( ) { return shipId; }
public void setShipId(int sid) { shipId = sid; }

@Column(name="BED_COUNT")
public int getBedCount( ) { return bedCount; }
public void setBedCount(int bed) { bedCount = bed; }

}

Persistance.xml

<?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">
<jta-data-source>mysql</jta-data-source>
<properties/>
</persistence-unit>
</persistence>


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;

@Remote
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;

@Stateless

@RemoteBinding
(jndiBinding="TravelAgentRemote")

public class TravelAgentBean implements TravelAgentRemote{
@PersistenceContext
(unitName="TestEJB")
private EntityManager manager;

public void createCabin(Cabin cabin) {
manager.persist(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)
PortableRemoteObject.narrow(ref,TravelAgentRemote.class);

Cabin cabin_1 = new Cabin( );
cabin_1.setId(1);
cabin_1.setName("Master Suite");
cabin_1.setDeckLevel(1);
cabin_1.setShipId(1);
cabin_1.setBedCount(3);

dao.createCabin(cabin_1);

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( );
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES,
" 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
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for the original question:

Object ref = getInitialContext().lookup("TestEJB/TravelAgentRemote");
TravelAgentRemote dao = (TravelAgentRemote)
PortableRemoteObject.narrow(ref,TravelAgentRemote.class);



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
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jaikiran,

You are correct, JBoss 5.0 Beta1 has JEE support.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic