4 Replies Latest reply on May 3, 2004 10:48 AM by rogerp

    finder error: Unknow query

    rogerp Newbie

      I am using JBuilder9 to generate CMP2.0 Entity Bean. I named the bean as Enterprise3.
      Then, I add a finder, findByFirstName(String firstName), with the query as
      "SELECT OBJECT (s) FROM person AS s WHERE s.firstName=(?1)"

      Howerver, whern I use

      Enterprise3Remote e3=client.findByFirstName("Jim");

      I encounter the following error message :
      javax.ejb.FinderException: Unknown query: public abstract trader.Enterprise3Remote trader.Enterprise3RemoteHome.findByFirstName(java.lang.String) throws javax.ejb.FinderException,java.rmi.RemoteException

      at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.getQueryCommand(JDBCQueryManager.java:60)

      at org.jboss.ejb.plugins.cmp.jdbc.JDBCFindEntityCommand.execute(JDBCFindEntityCommand.java:46)

      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.findEntity(JDBCStoreManager.java:571)

      at org.jboss.ejb.plugins.CMPPersistenceManager.findEntity(CMPPersistenceManager.java:299)

      ============================
      What could be worng?
      FindByPrimaryKey() works well. But other finder methods just fail.

        • 1. Re: finder error: Unknow query
          sesques Novice

          Did you define the query with the full parameter type:

          Enterprise3 findByFirstName(java.lang.String firstName)
          


          If yes, post more infos (ejb-jar and jbosscmp-jdbc descriptors)
          Pascal


          • 2. Re: finder error: Unknow query
            rogerp Newbie

            I tried to use java.lang.String insteda of Stirng. But still failed.

            the ejb-jar.xml and jbosscmp-jdbc.xml are as followings:

            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
            <ejb-jar>
            <enterprise-beans>

            <display-name>Enterprise3</display-name>
            <ejb-name>Enterprise3</ejb-name>
            trader.Enterprise3RemoteHome
            trader.Enterprise3Remote
            <local-home>trader.Enterprise3Home</local-home>
            trader.Enterprise3
            <ejb-class>trader.Enterprise3Bean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>trader.Enterprise3PK</prim-key-class>
            False
            <cmp-version>2.x</cmp-version>
            <abstract-schema-name>Enterprise3</abstract-schema-name>
            <cmp-field>
            <field-name>pId</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>firstName</field-name>
            </cmp-field>

            <query-method>
            <method-name>findByFirstName</method-name>
            <method-params>
            <method-param>java.lang.String</method-param>
            </method-params>
            </query-method>
            <ejb-ql>select object (s) from person as s where s.firstName="Jim"</ejb-ql>


            </enterprise-beans>
            <assembly-descriptor>
            <container-transaction>

            <ejb-name>Enterprise3</ejb-name>
            <method-name>*</method-name>

            <trans-attribute>Required</trans-attribute>
            </container-transaction>
            </assembly-descriptor>
            </ejb-jar>

            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">
            <jbosscmp-jdbc>

            MySQLDS2
            <datasource-mapping>mySQL</datasource-mapping>

            <enterprise-beans>

            <ejb-name>Enterprise3</ejb-name>
            <table-name>person</table-name>
            <cmp-field>
            <field-name>pId</field-name>
            <column-name>personId</column-name>
            </cmp-field>
            <cmp-field>
            <field-name>firstName</field-name>
            </cmp-field>

            </enterprise-beans>
            </jbosscmp-jdbc>

            Many Thanks.^_^

            • 3. Re: finder error: Unknow query
              sesques Novice

              In EJB-QL, the FROM clause must refers to the bean, not the table.
              So the query must be:

              <query>
              <query-method>
              <method-name>findByFirstName</method-name>
              <method-params>
              <method-param>java.lang.String</method-param>
              </method-params>
              </query-method>
              <ejb-ql>select object (s) from Enterprise3 as s where s.firstName=?1</ejb-ql>
              </query>
              
              


              • 4. Re: finder error: Unknow query
                rogerp Newbie

                You are very very very right!
                I should use bean name instead of table name. My problem is solved!
                Pascal, thank you very very much!