File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Annotation @Stateful in EJB 3.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Annotation @Stateful in EJB 3.0" Watch "Annotation @Stateful in EJB 3.0" New topic
Author

Annotation @Stateful in EJB 3.0

Jagadeesan Sampath
Greenhorn

Joined: Sep 05, 2007
Posts: 1
Hi I am new bie,

The stateful bean and Interface are as follows.
-----------------------
package business;

import java.util.Collection;
import javax.ejb.Remote;

@Remote
public interface Cart {
public void addItem(String item);
public void removeItem(String item);
public Collection getItems();
public void listItem(Collection stuff);
}
------------------
package business;

import java.util.ArrayList;
import java.util.Collection;
import javax.annotation.PostConstruct;
import javax.ejb.Stateful;
import javax.ejb.Remote;
import java.util.Iterator;

@Stateful(mappedName="CartEJB")
@Remote(Cart.class)
public class CartBean implements Cart {
private ArrayList items;
private Collection stuff;
@PostConstruct
public void initialize() {
items = new ArrayList();
}

public void addItem(String item) {
items.add(item);
}

public void removeItem(String item) {
items.remove(item);
}

public void listItem(Collection stuff) {
for (Iterator i = items.iterator(); i.hasNext() {
String item = (String) i.next();
System.out.println(" " + item);
}
}

public Collection getItems() {
return items;
}
}
-------------

The jar built with these 2 is succesfully deployed in JBoss

When a standalone client tried to access the CartBean with the mappedname attribute it gives the below exception

javax.naming.NameNotFoundException: CartEJB#Cart 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:296)
at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at CartClient.main(CartClient.java:31)

I am using lookup like this

ctx.lookup (CartEJB#Cart)

Not sure if I have to make the request in JBoss forum. Please advice

Rgds
JS
[ September 05, 2007: Message edited by: Jagadeesan Sampath ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Annotation @Stateful in EJB 3.0