Passing parameters by reference

Discussions

EJB design: Passing parameters by reference

  1. Passing parameters by reference (10 messages)

    Hi

    I saw many threads that say that passing object by reference (i.e.
    objects that implements the
    java.rmi.Remote interface) to an EJB is not conform to the EJB
    specification. But I did not found
    this restriction in the spec. So can someone tell me :

    1. is this really forbidden ?
    2. if yes where, in the specification, such restriction is mentioned ?

    Thanks in advance


    --
    Olivier Duhart
    Wokup! - Product Team
    olivier dot duhart at wokup dot com
    +33 299 844 412

    Threaded Messages (10)

  2. Passing parameters by reference[ Go to top ]

    Yes this is illegal. All variables must be passed by copy not by reference. This is shown in Section B.9 :

    "The enterprise bean’s home and remote interfaces are remote interface in the Java RMI sense. The Con-tainer
    must ensure the Java RMI argument passing semantics. Non-remote objects must be passed by
    value.

    Specifically, the EJB Container is not allowed to pass local objects by reference on inter-enterprise bean
    invocations when the calling and called enterprise beans are collocated in the same JVM. Doing so
    could result in the multiple beans sharing the state of a Java object, which would break the enterprise
    bean’s semantics."

    Dave Wolf
    Internet Applications Division
    Sybase
  3. Passing parameters by reference[ Go to top ]

    Hi Dave,

    First this section is in ... the FAQ which is not exactly
    a specification for me.

    Second this "specification" says that you can't pass object
    by reference between beans but between a servlet (for
    example in my case) and an EJB ?

    Olivier
  4. Hi

    Passing by reference is possible but the condition is that the object should be implemented the serializable interface. I hope i am correct. If i am wrong plese correct me.

    Regards
    Sankar
  5. Hi

    Passing by reference is possible but the condition is that the object should be implemented the serializable interface. I hope i am correct. If i am wrong plese correct me.

    Regards
    Sankar
  6. Hi Sankar

    I'm sorry but you're wrong. If an object implements the
    Serializable interface then it is passed by copy.

    Olivier
  7. Passing parameters by reference[ Go to top ]

    It is listed outside this appendix, and Ill find that for you in a moment. However the impertive line is

    "The enterprise bean’s home and remote interfaces are remote interface in the Java RMI sense. The Con-tainer
    must ensure the Java RMI argument passing semantics. Non-remote objects must be passed by
    value. "

    Non-remot objects MUST be passed by value. Only home/remote are passed by reference.

    Dislike it as you might, this is the spec as it stands today.

    Dave Wolf
    Internet Applications Division
    Sybase
  8. Passing parameters by reference[ Go to top ]


    >"The enterprise bean’s home and remote interfaces
    > are remote interface in the Java RMI sense. The Con-
    > tainer
    > must ensure the Java RMI argument passing semantics. Non-
    > remote objects must be passed by
    > value. "

    > Non-remot objects MUST be passed by value. Only
    > home/remote are passed by reference.


    So you can pass an object by reference (in the RMI sense)
    if this object implements java.rmi.Remote. Am i wrong ?

    Olivier
  9. Passing parameters by reference[ Go to top ]

    Except in EJB only the home and remote can implement Remote and be passed like a remote. All parameters and return types MUST (the spec is extreemely clear here) ba passed by copy.

    Another reason we know this is Sybase EAServer is J2EE branded and this issue is in the compatability test suite.

    Net net is ONLY homes and remotes may be passed by reference.

    Dave Wolf
    Internet Applications Division
    Sybase
  10. Passing parameters by reference[ Go to top ]

    Dave

    Sure, a non-remote object must be passed by value, but what's to stop you from making it a remote object by implementing java.rmi.remote? Surely all remote object in the ejb server do not have to be enterprise beans?

    Personally I can't think of a reason for doing this, but I can't see why one shouldn't be able to do it. Does that mean you can't have a bean that returns a reference to a non ejb object? How will the problem manifest itself?

    Regards

    James
  11. Passing parameters by reference[ Go to top ]

    Reading SUN's EJB specs on the fuzzy rule on passing objects around, I believe SUN did not say no to the question. It does emphasize on passing non-remote objects by value, but it doesn't say the bean's home and remote objects are the only ones allowed to be remote objects. The idea of creating home and remote object interfaces is to shield the bean instance away from its clients' direct control and access. That's one of the fundermentals of EJB. Allowing remote references breaks the rule. Just think about the situation that if your remote object holds a reference to an object inside an EJB bean instance. How could the EJB container passivate the bean instance when there is an active reference to it? If you call a method in the remote object when the bean instance is passivated, how does the EJB container detect the call and activate it while the method is out of the container's supervise? So I guess it's a use-it-at-your-own-risk scenario. It's only my guess, I never wrote a bean to verify it.


    Regards,

    Paul