2 Replies Latest reply on Aug 6, 2003 8:42 AM by Scott Stark

    Test of selectAccomplices MISSING in Jboss321 documentation:

    kutter Newbie

      I am using the Jboss 3.2.1 documentation. After this I started with a real project, and found that I have problems with a finder method that has an object as parameter.

      In your payed documentation there is one example
      for this, the finder method selectAccomplices.

      Part of your GangsterBean.java is:

      public abstract Set ejbSelectAccomplices(Gangster g) throws FinderException;

      But a lot is MISSING here...

      What is already MISSING, is that you include the
      finder in the GangsterHome.java. I did this
      as follows:

      //new:
      Set selectAccomplices(Gangster g) throws FinderException;

      Now the hard part starts, for someone who wants
      to use the docu. You have to find out that you have
      to add:

      //new:
      public Set ejbHomeSelectAccomplices(Gangster g) throws FinderException {
      return ejbSelectAccomplices(g);
      }

      to the GangsterBean. I cannot see how someone new
      to the field can find it out. I lost quite a lot of time.

      Then, testing is easy, adding to the CrimePortalTest:

      /** Test Organization-Gangster relationship */
      public void testAccomplices() throws Exception
      {
      Gangster yojimbo = gangsterHome.findByPrimaryKey(YOJIMBO);
      Set all = gangsterHome.selectAccomplices(yojimbo);
      for (Iterator iter = all.iterator(); iter.hasNext();) {
      Gangster element = (Gangster) iter.next();
      System.out.println(element);
      }

      }


      SIMPLER SOLUTION:
      I think, it would anyhow be simpler to do the following:

      Add to ejb-jar.xml:


      <query-method>
      <method-name>findAccomplices2</method-name>
      <method-params>
      <method-param>org.jboss.cmp2.crimeportal.Gangster</method-param>
      </method-params>
      </query-method>
      <ejb-ql>[CDATA[
      SELECT DISTINCT OBJECT(g)
      FROM gangster g, IN(g.jobs) j, IN(j.gangsters) accomplice
      WHERE g = ?1 AND accomplice <> ?1
      ]]</ejb-ql>


      Add to GangsterHome.java:

      Collection findAccomplices2(Gangster g) throws FinderException;


      And test as follows:

      /** Test Organization-Gangster relationship */
      public void testAccomplices2() throws Exception
      {
      Gangster yojimbo = gangsterHome.findByPrimaryKey(YOJIMBO);
      Collection all = gangsterHome.findAccomplices2(yojimbo);
      for (Iterator iter = all.iterator(); iter.hasNext();) {
      Gangster element = (Gangster) iter.next();
      System.out.println(element);
      }

      }


      You should absolutly add this to the docu. My copyright you get for free, and I hope you improve the docu considerably!

      For instance, you should deliver the example as Xdoclet
      projects, using your Jboss Ide. Took me a while to
      learn the tools and reengineer your example at once.

      Philipp


        • 1. CORRECTION, but in 3.2.1 Documentation
          kutter Newbie

          of course it has to be DISTINCT OBJECT(accomplices)
          and not OBJECT(g), as written in the JBoss3.2.1
          documentation.

          Philipp

          • 2. Re: CORRECTION, but in 3.2.1 Documentation
            Scott Stark Master

            The first approach is wrong because you are trying to make a select method available from the home and this is not what select methods are for. They are only for internal use by the bean implementation class. You simply found a convoluted way to expose a non-standard home method, and this is a failure of the validation layer to detect it.

            The second approach which exposes this operation as a finder on the home is the correct way to do this.

            See the O'Reilly JBoss 3.0 Workbook for info on xdoclet.