Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Handling Parameters

This section describes the following:

Passing Parameters Into an Enterprise Bean

When you implement an enterprise bean or write the client code that calls EJB methods, you must be aware of the parameter-passing conventions used with enterprise beans.

A parameter that you pass to a bean method (or a return value from a bean method) can be any Java type that is serializable. Java primitive types, such as int, double, are serializable. Any nonremote object that implements the java.io.Serializable interface can be passed. A nonremote object that is passed as a parameter to a bean, or returned from a bean, is passed by value, not by reference. So, for example, if you call a bean method as follows:

public class theNumber {
   int x;
}
...
bean.method1(theNumber);

then method1() in the bean receives a copy of theNumber. If the bean changes the value of theNumber object on the server, this change is not reflected back to the client, because of pass-by-value semantics.

If the nonremote object is complex (such as a class containing several fields) only the nonstatic and nontransient fields are copied.

When passing a remote object as a parameter, the stub for the remote object is passed. A remote object passed as a parameter must extend remote interfaces.

The next section demonstrates parameter passing to a bean, and remote objects as return values.

Handling Parameters Returned by an Enterprise Bean

The EmployeeBean method getEmployee returns an EmpRecord object, so this object must be defined somewhere in the application. In this example, an EmpRecord class is included in the same package as the EJB interfaces.

The class is declared as public and must implement the java.io.Serializable interface so that it can be passed back to the client by value as a serialized remote object. The declaration is as follows:

package employee;

public class EmpRecord implements java.io.Serializable {
  public String ename;
  public int empno;
  public double sal;
}

Note:

The java.io.Serializable interface specifies no methods; it just indicates that the class is serializable. Therefore, there is no need to implement extra methods in the EmpRecord class.