4 Replies Latest reply on Sep 3, 2006 11:21 AM by ianfmc

    Basic CMR Question

    ianfmc

      Hi Everyone:

      I'm fairly new to J2EE, so this may be a very basic question. I apologize in advance.

      I have successfully defined an EJB that reads a table in the HSQL, and correctly reports the values from that table.

      As an exercise, I added a second table with a 1:1 relationship to the first, which both have a common ID field. In the first table (Player) this is primary-key (PlayerID), and in the second table (Ranking), it is the foreign-key (also PlayerID). The other two fields in the Player Table are: FirstName and LastName. In the Ranking Table, there are two fields: PlayerID and Ranking.

      I created a container managed relation (CMR) using the wizard in Jboss-IDE, but when I now try to get all Player records, I get the following Exception

      java.sql.SQLException: Column not found: RANKING in statement [SELECT playerID, lastName, firstName, ranking FROM PLAYER WHERE (playerID=?) OR (playerID=?) OR (playerID=?)]
      


      I define the method findAllPlayers() using XDoclet as follows

       * @ejb.finder
       * query = "SELECT OBJECT(b) FROM Player AS b"
       * signature = "java.util.Collection findAllPlayers()"
      



      the XDoclet tag in the first Bean (PlayerBean) looks like this:

      /**
       * Getter for CMR Relationship
       *
       * @ejb.interface-method view-type="remote"
       * @ejb.relation name = "Player-Ranking"
       * role-name = "Player_Has_A_Ranking"
       * target-ejb = "Ranking"
       * target-role-name = "Ranking"
       * target-multiple = "no"
       */
       public abstract String getRanking();
      


      Any advice would be greatly appreciated!

      Thanks, Ian.

        • 1. Re: Basic CMR Question
          bronks

           

          "ianfmc" wrote:
          ...

          ...
           * @ejb.interface-method view-type="remote"
           ...
          



          CMR-Methods have always to be local. Perhaps this is the reason.

          • 2. Re: Basic CMR Question
            ianfmc

            Hi! Thanks for the reply, very much...

            When I switch that method to "Local," I can't call it then from the Session Bean. Is the better strategy to use a Select Method, and then wrap that?

            Something like this?

            player.getRanking();
            ...
            
            public String getRanking()
            {
             return ejbSelectRanking(this.playerID);
            }
            


            • 3. Re: Basic CMR Question
              ianfmc

              Or...is a better strategy to make the Entity Beans all local, and expose the Session Beans as 'remote?'

              Thanks again!!

              • 4. Re: Basic CMR Question
                ianfmc

                So, ultimately I think the problem is with the EJB-QL, so I am starting another thread for that...