I have a remote ejb which takes an object. It modifies the data in that object using the setter methods. In the client, I printed the value by using a getter method and observed that the value has changed.
But the documentation here says that the parameters are isolated. Can anyone please explain?
@Remote
public class RemoteServiceBean {
public Student parameterIsolationTest(final Student student) {
student.setName("modified");
return student;
}
}
public class MyClient {
public static void main(String arg...) {
....
Student student = new Student();
student.setName("Krishna");
remoteService.parameterIsolationTest(student);
System.out.println(student.getName()); // prints modified
}
}
The bean on the server side operates with Java objects existing in the JVM of the server. The client has a different JVM and therefore a different set of objects. When you do remote EJB invocations, these objects need to be 'transferred' somehow to the client and back. The thing is that this 'transfer' occurs only during EJB invocations themselves. So if your client invokes a setter on an EJB, the other object will be sent to the server, but if the client modifies this object afterwards (without invoking anything on the EJB bean), the client's object will NOT be transferred to the server - the server will not know that the client changed the object.
If I understand your scenario, you are invoking a setter on an EJB and then the getter for the same property. Setters and getters are both methods of the EJB, so this will include EJB calls and the changes you make from the client will propagate to the server in this case.