2 Replies Latest reply on Aug 4, 2003 11:52 AM by Chris Lamprecht

    Can not get Collection field in client

    Kimber Ji Newbie

      Hi, I create two EntityBean StudentBean and CourseBean. The relationship between them is one to many which means that one StudentBean can have many CourseBean. Also I create a client to test the relationship.But when I call function getCourses,error occurses.The Error message is:

      at $Proxy2.getCourses(Unknown Source)
      at first.client.Test.main(Test.java:75)
      Caused by: java.io.NotSerializableException: org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
      at java.rmi.MarshalledObject.(MarshalledObject.java:92)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:363)
      at sun.reflect.GeneratedMethodAccessor68.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:536)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
      at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
      at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:87)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
      at org.jboss.proxy.ejb.EntityInterceptor.invoke(EntityInterceptor.java:97)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
      ... 2 more

      It seems that Collection is not Serializable .

      I define the getCourses like the following:
      * @ejb.interface-method view-type = "both"
      * @ejb.relation
      * name = "StudentCourse"
      * role-name = "Student-Select-Many-Courses"
      * target-ejb = "CourseEJB"
      * target-role-name = "Many-Course-Selected-By-One-Student"
      * target-multiple = "no"
      * target-cascade-delete = "no"
      public abstract java.util.Collection getCourses();

      * @ejb.interface-method view-type = "both"
      public abstract void setCourses(java.util.Collection courses);



        • 1. Re: Can not get Collection field in client
          Bernd Zeitler Expert

          I seems that the collection is not serializable, which could even mean the content is not serializable.
          Remember, you can't hand out (to the client) bean references, since these are stubs to server side components.
          Best pracitce is to do all the work on the server. If you really have to hand out beans, use the bean handles.


          • 2. Re: Can not get Collection field in client
            Chris Lamprecht Newbie

            I believe CMR collection fields are only available to clients using the Local interface (not the remote interface). Also, CMR collections are only available within the current transaction. Once the transaction ends, that Collection becomes invalid (I believe this is correct -- someone correct me if I am wrong).

            I would like to hear from some CMP experts on how they deal with these limitations. I had the exact same problem (with students and courses, oddly enough!), and the way I solved it was to have a session facade bean access the CMR collection, and built a new copy of the collection containing all value objects, and send that to the remote client. Is this a decent solution? Is there a better solution, anyone? Thanks