7 Replies Latest reply on Sep 25, 2002 3:37 PM by dsundstrom

    FinderException: Unknown Query

    markuspr

      Hi!

      I've created a new PersonBean, having an Id, First_Name and Last_Name. I can insert a person and find it by its Id (primary key). To do so I use the findByPrimaryKey(test.interfaces.PersonPK) method of the home interface. PersonPK is generated by Ant/Xdoclet.
      But when I try to find it by a findByName method it throws FinderException: Unknown Query.
      I've used the following code in my PersonBean:

      [...]
      * @ejb:finder signature="java.util.Collection findAll()"
      *
      * @ejb:finder signature="test.interfaces.Person findByName( java.lang.String pFirstName, java.lang.String pLastName )"
      *
      * @jboss:finder-query name="findByName"
      * query="First_Name = {0} AND Last_Name = {1}"
      [...]

      The get-methods (here: getFirstName) have the following source and they are all correct:
      [...]
      * @ejb:persistent-field
      *
      * @jboss:column-name name="First_Name"
      [...]

      My TestClient uses:

      InitialContext lContext = new InitialContext();
      PersonHome lHome = (PersonHome) lContext.lookup("ejb/test/Person");
      Person lPerson = lHome.findByName("My", "Name");

      This project is a modified "template"-project you can download together with the documentation. Can someone help me? Thanks!

      CU Markus

        • 1. Re: FinderException: Unknown Query
          dsundstrom

          Are you using CMP 2.0? If so, you MUST use XDoclet from the XDoclet cvs head. The previous version are broken for JBossCMP.

          The problem you are having is you are using the old JAWS style tags with JBossCMP and XDoclet is delcaring the finder in the jaws.xml file which is no longer loaded. For CMP 2.0 you should use ejb-ql queries.

          • 2. Re: FinderException: Unknown Query
            markuspr

            I've tried to use ejb-ql queries, but now JBoos doesn't deploy my files anymore. I get the following error:

            14:13:41,942 ERROR [EjbModule] Starting failed
            org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "PersonBean" at line 1, column 37.
            Was expecting one of:
            "IN" ...
            <ABSTRACT_SCHEMA> ...
            )
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.(JDBCEJBQLQuery.java:46)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createEJBQLQuery(JDBCCommandFactory.java:44)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager.java:214)
            [...]


            I've used to following code:

            /**
            * This bean represents a Person
            *
            * @ejb:bean name="test/Person"
            * display-name="Person working on projects to support clients"
            * type="CMP"
            * jndi-name="ejb/test/Person"
            *
            * @ejb:env-entry name="SequenceName"
            * value="Person"
            *
            * @ejb:ejb-ref ejb-name="test/SequenceGenerator"
            *
            * @ejb:transaction type="Required"
            *
            * @ejb:data-object extends="test.interfaces.AbstractData"
            * setdata="false"
            *
            * @ejb:finder signature="test.interfaces.Person findByLastName(java.lang.String lastName)"
            * query="SELECT DISTINCT OBJECT(person) FROM PersonBean person where person.Last_Name = 'myname'"
            * result-type-mapping="Local"
            *
            * @jboss:table-name table-name="Person"
            *
            * @jboss:create-table create="true"
            *
            * @jboss:remove-table remove="true"
            **/


            I can also use the following query but that doesn't help:

            query="SELECT DISTINCT OBJECT(person) FROM PersonBean person where person.Last_Name = ?1"

            I think I've done the right job, because these querys are from the net and tested a thousand times. Can you help only one more time, please :-)

            Thanks, Markus

            • 3. Re: FinderException: Unknown Query
              dsundstrom

              You did not declare an abstract-schema-name for you bean.

              • 4. Re: FinderException: Unknown Query
                markuspr

                I've tried to following code, too:

                /**
                * This bean represents a Person
                *
                * @ejb:bean name="test/Person"
                * display-name="Person working on projects to support clients"
                * type="CMP"
                * view-type="remote"
                * jndi-name="ejb/test/Person"
                * schema="Person"
                *
                * @ejb:env-entry name="SequenceName"
                * value="Person"
                *
                * @ejb:ejb-ref ejb-name="test/SequenceGenerator"
                *
                * @ejb:transaction type="Required"
                *
                * @ejb:data-object extends="test.interfaces.AbstractData"
                * setdata="false"
                *
                * @ejb:finder signature="test.interfaces.Person findByLastName(java.lang.String lastName)"
                * query="SELECT OBJECT(o) FROM Person AS o WHERE o.last_Name = ?1"
                *
                * @jboss:finder-query name="findByLastName"
                * query="Last_Name = {0}"
                *
                * @jboss:table-name table-name="Person"
                *
                * @jboss:create-table create="true"
                *
                * @jboss:remove-table remove="true"
                **/


                But I got that exception this time:

                19:10:34,923 ERROR [EjbModule] Starting failed
                org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.UnknownPathException: Unknown terminal field: at line 1, column 51. Encountered: "last_Name" after: "o.")
                at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.(JDBCEJBQLQuery.java:46)
                at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createEJBQLQuery(JDBCCommandFactory.java:44)
                at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager.java:214)
                at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:389)


                That's why I thought this can't be the solution of my problem... Ufff, sometimes I think JBoss really hates me! :-)
                Do you perhaps have an CMP2 bean which is working so that I can compare what to do?

                Thanks, Markus

                • 5. Re: FinderException: Unknown Query
                  dsundstrom

                  Do you have the methods getLast_Name and setLast_Name? I would bet that you actually have methods named getLastName and setLastName. In this case the correct EJB-QL follows:

                  SELECT OBJECT(o)
                  FROM Person AS o
                  WHERE o.lastName = ?1

                  I suggest you get a good book on EJB. As for working code, I don't have many examples that use XDoclet as I just started using it. The only good example I know of is in the applications cvs module under forums.

                  • 6. Re: FinderException: Unknown Query
                    markuspr

                    Thanks for your help! Now it really works!

                    My problem was that the JBoss column-name is Last_Name and the methods name LastName. I don't know why, but the template example is coded like that. The example isn't working as well that's why I was confused.

                    I have read "Enterprise Java Beans" by Monson-Haefel (O'Reilly) and I think that this is a good book, but I'm using XDoclet that's why I need a book like "Enterprise Java Beans: Using JBoss & XDoclet" :-)
                    The examples of the book are working very well, but if you use XDoclet you need to know how to use the tags correctly and how they work correctly together with JBoss - and that was my problem.

                    But now the JBoss gods seem to be favourably disposed towards me again :-)

                    Thanks once more for your help,
                    Markus

                    • 7. Re: FinderException: Unknown Query
                      dsundstrom

                      > I have read "Enterprise Java Beans" by
                      > Monson-Haefel (O'Reilly) and I think that this is a
                      > good book, but I'm using XDoclet that's why I need a
                      > book like "Enterprise Java Beans: Using JBoss &
                      > XDoclet
                      " :-)

                      I'll tell him next time I see him (we live in the same city).

                      -dain