4 Replies Latest reply on Aug 9, 2002 6:02 AM by Colin Yates

    jboss get() for foreign key on 1-m CMR fails

    Colin Yates Newbie

      Hi,

      I have defined a 1 to many relationship between class One and class Many.

      The relationship is stored via a foreign key in Many called Many.username. The primary key on One is One.username.

      I have a load of other get/sets managed by the container and they all work fine, but if I call Many.getUsername() it throws exception about the field not being a CMR or CMP accessor!

      Any ideas? The field is definately there and the relationship works fine. Given the many, I want to know the fk of the One!

      Thanks

        • 1. Re: jboss get() for foreign key on 1-m CMR fails
          Dain Sundstrom Master

          This means that the mapping is not setup correctly in the ejb-jar.xml file, because JBossCMP does not know about the abstract accessor. Did you declare a cmp field accessor for 'username' (case counts) in the ejb-jar.xml file.

          • 2. Re: jboss get() for foreign key on 1-m CMR fails
            Colin Yates Newbie

            I used the following xdoclet definition on the "One" side:

            /**
            * @return all the criteria for this report
            *
            * @ejb:interface-method view-type="local"
            * @ejb:relation
            * name="report-criteria"
            * role-name="one-report-has-many-criteria"
            * target-role-name="one-criteria-belongs-to-one-report"
            * target-ejb="SavedReportCriteria"
            * target-multiple="no"
            * target-cascade-delete="yes"
            *
            * @jboss:target-relation related-pk-field="id"
            * fk-column="reportid"
            */
            public abstract Collection getCriteria();

            /**
            * set criteria for this report
            *
            * @ejb:interface-method
            */
            public abstract void setCriteria(Collection criteria);

            Funny thing is that it all works fine (except the getUsername())

            • 3. Re: jboss get() for foreign key on 1-m CMR fails
              Eric Isakson Newbie

              When you use the get for the relation from the many side, you should be getting the local interface representing the one side of the relation, not its primary key. I've read several times on this forum that you can't get the foreign key in the cmr relation as a cmp field (which I think is what you are asking for).

              I suppose you could add a method to your Many object like:

              public String getUsername() {
              // get the CMR One object related to this Many
              OneLocal one = getOne();
              // get its CMP field "username"
              return one.getUsername();
              }

              • 4. Re: jboss get() for foreign key on 1-m CMR fails
                Colin Yates Newbie

                So do I declare "OneLocal getUsername()"? Do I mark that method as CMP or not?

                I don't suppose you have the xdoclet tag do you :)?

                Thanks a lot.