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 returning a class from an session ejb 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 "returning a class from an session ejb" Watch "returning a class from an session ejb" New topic

returning a class from an session ejb

Sergio Barreros

Joined: Sep 09, 2003
Posts: 21
I have an session ejb(MyEJB) that calls a class(skuObj.class) with a bunch of getters and setters, I retrieve a record from the database and set the row to the class like this skuObj.setSKU(the value from db).. and so on.
after that I return the class object.So my ejb Method looks like this;
public skuObj getSku(String _sku_cd) throws EJBException {
skuObj sku = new skuObj();
sql = "select * from sku where sku_cd = '" + _sku_cd + "'";

return sku;
The EJB resides in a Jboss server, so If I call the EJB from the local server, I have no problem. The problem is tha I need to call the EJB from a remote server running tomcat, I get a error. I know I need to serialize the skuObj.class object in order to pass it to the remote server, and I have been looking for an example on this, but can't find any.
Is this even possible? I am quite sure it is possible, but I can not find an kind of reference to this and that is making me think otherwise.
Thanks for any help provided!
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
Firstly, there's no reason to declare that your getSku method throws an EJBException because EJBExceptions are runtime exceptions and are not checked.
Secondly, you don't have to do much to get your SkuObj to be Serializable. You just need two things: 1) make the SkuObj class implements 2) Make sure that your client has the SkuObj class available to it because it will need this class to reconstruct the skuObj once it receives it.
You don't explicitly write code to serialize any parameters or return values. This is done for you by the rmi implementation.

Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
And to clarify your post, you are not returning the *class*. You are returning an instance of the SkuObj class -- an object in simple terms. AFAIK, RMI will not pass along classes with serialized objects. Instead, you must ensure that the client has access to the SkuObj class in its classpath.
Sergio Barreros

Joined: Sep 09, 2003
Posts: 21
Thanks guys, reading about serializing other objects and looking at examples that you had to write code to serialze them and then reconstruct them was making me think I had to write some code to achieve this.
I got it to work, thanks!
I agree. Here's the link:
subject: returning a class from an session ejb
It's not a secret anymore!