5 Replies Latest reply on Nov 12, 2002 12:31 PM by arnaud jamin

    CMP2 relation : java.lang.ClassCastException

    arnaud jamin Newbie

      Hello, using Jboss-3.0.3 with Xdoclet-1.1.2, I've 2 EntityBean :
      - ProjectBean
      - UserBean

      A project must be directed by a User called a director.
      So i've a relation between my Beans.

      Here is the relation in the side of the ProjectBean :

      /**
      * @ejb:interface-method view-type="remote"
      * @ejb.relation name="director-project" role-name="project-has-director"
      * @jboss.relation-mapping style="foreign-key"
      * @jboss.relation fk-constraint="true" fk-column="director_fk" related-pk-field="id"
      **/
      public abstract User getDirector();
      public abstract void setDirector(User director);


      And here is the relation in the side of the UserBean:

      /**
      * @ejb.interface-method view-type="remote"
      * @ejb.relation name="director-project" role-name="director-has-project"
      * @jboss.relation-mapping style="foreign-key"
      */
      public abstract java.util.Collection getDirectedProjects();
      public abstract void setDirectedProjects(java.util.Collection);


      Finaly, here are my Project's ejbCreate and ejbPostCreate methods:

      public ProjectPK ejbCreate(ProjectData pProject, User director) throws ....
      {...}

      public void ejbPostCreate(ProjectData pProject, User director)
      {
      Debug.print("ProjectBean ejbPostCreate");
      setDirector(director);
      Debug.print("ProjectBean ejbPostCreate end");
      }


      Well, just after the "ProjectBean ejbPostCreate" debug, I get the following expection :

      ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
      java.lang.ClassCastException: $Proxy113


      So I guess i'm doing wrong, but i don't know where.
      If anyone has an idea, or an exemple.

      Thanks.

        • 1. Re: CMP2 relation : java.lang.ClassCastException
          Jeremy Boynes Newbie

          I'm guessing from the information you've supplied that User is the remote interface for your UserBean. If so it won't work as CMR requires you use the local interface.

          • 2. Re: CMP2 relation : java.lang.ClassCastException
            arnaud jamin Newbie

            Thanks, I'll look at the local interface.
            What I don't understand is why the Jboss PDF documentation show this example :


            public abstract class OrganizationBean implements EntityBean {
            public abstract Set getMemberGangsters();
            public abstract void setMemberGangsters(Set gangsters);
            }

            public abstract class GangsterBean implements EntityBean {

            public abstract Organization getOrganization();
            public abstract void setOrganization(Organization org
            );
            }


            Should it be :


            public abstract class OrganizationBean implements EntityBean {
            public abstract Set getMemberGangsters();
            public abstract void setMemberGangsters(Set gangsters);
            }

            public abstract class GangsterBean implements EntityBean {
            public abstract OrganizationLocal getOrganization();
            public abstract void setOrganization(OrganizationLocal org);
            }


            Thanks.

            • 3. Re: CMP2 relation : java.lang.ClassCastException
              arnaud jamin Newbie

              Thanks for the answer.

              It seems to work fine, but now i'm mixing the use of "localHome" and "RemoteHome".

              So I just like to know why is the use of remoteHome since you can use LocalHome.

              When should I use the remoteHome and when should i use the LocalHome?

              (I hope my question is just not too stupid)

              Thanks again.

              • 4. Re: CMP2 relation : java.lang.ClassCastException
                Jeremy Boynes Newbie

                The examples define Organization as a local interface - it's just xdoclet's convention to use X for remote and XLocal for local.

                The spec restricts CMR to local interfaces to restrict CMP implementation to a single container - if it didn't the persistence manager would need to be interoperable between VMs (and vendors) which is probably unnecessary complexity.

                I try and use local interfaces wherever I can - basically wherever I don't anticipate needing remote invocation. Check out the Session Facade pattern. Your mileage may vary - there's no one answer here.

                • 5. Re: CMP2 relation : java.lang.ClassCastException
                  arnaud jamin Newbie

                  Thank you very much for your help.