简体   繁体   中英

Modifying arguments in remote EJB method

There are a lot of articles describing how modifications to EJB method arguments are not passed to the caller. I usually resolve this by returning the argument to the caller so it can be reassigned to a variable.

My problem is that none of the articles seem to describe what I should do in more complex methods where I need to make modifications to arguments and return some value. I could make some sort of wrapper class that contains property for each argument and the actual return value and return the wrapper, but that seems very clumsy to me. Are there better ways to accomplish this?

There are no other ways.

Imagine the following method:

Result doSomething(A arg1, B arg2, C arg3) { 
  ...
}

Because you are calling your EJB using remote connection, the client will serialize arg1 , arg2 and arg3 . At this point, they are completely new instance, say arg1' , arg2' and arg3' .

They are probably not even on the same JVM, and if it were, you should not rely on that (some EJB container use reference when they determine that caller and called are in the same JVM).

Returning a Result , taking those argN' updated is the only way:

Result doSomething(A arg1, B arg2, C arg3) {
  ...      
  return new Result(arg1, arg2, arg3);
}

Then the container will serialize Result , and arg1' , arg2' and arg3' , and the caller will receive Result' containing arg1" , arg2" and arg3" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM