3 Replies Latest reply on Apr 23, 2004 6:05 AM by ahardy66

    CMP finder methods

    ahardy66


      Am I right in thinking that I have to return a Collection from all of my finder methods except findByPrimaryKey()?

      In the DB I have a users table with a userId and a loginName. Both have unique constraints on them, but only the Id is the primary key.

      If I want to create a findByUserName() then does it have to return a collection, out of which I must fish the bean?

      Or can I do it some other way and return just the one bean? I'm using xdoclet and this isn't working:

      * @ejb.finder
       * description="get user by name"
       * signature="org.gargantus.user.UserLocal findByUserName(String name)"
       * query="SELECT OBJECT(u) FROM user AS u WHERE u.userName = ?1"
      


        • 1. Re: CMP finder methods
          clajoie

          No, Finder methods can return single beans. You just need to make sure that the query you execute will in fact only return one row or else you'll get an exception. Here's a snippet of XDoclet on a bean that finds a person by social security number and returns just a single Person bean

           * @ejb.finder
           * signature="Person findBySsn(java.lang.String ssn)"
           * query="SELECT OBJECT(p) FROM Person p WHERE p.ssn = ?1"
          


          Is UserLocal the local interface of a bean named User? If so try returning just User.

          • 2. Re: CMP finder methods
            petino

            A correction: finder query which returns object should return _at_most_ one row. (hint: 0 rows for ObjectNotFound)

            • 3. Re: CMP finder methods
              ahardy66


              Grand. Thanks for the advice.

              Petino - what are you hinting? No comprendo, senor.


              Adam