|
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3) B14428-01 |
|
![]() Previous |
![]() Next |
This section describes:
When you implement an EJB or write the client code that calls EJB methods, you must be aware of the parameter-passing conventions used with EJBs.
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 non-remote object that implements the java.io.Serializable interface can be passed. A non-remote 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 non-remote object is complex—such as a class containing several fields—only the non-static and non-transient 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.
The EmployeeBean getEmployee method 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: Thejava.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.
|