9 Replies Latest reply on May 9, 2004 9:22 AM by sesques

    Unknown query error on finder method

    hendrik1

      Hi all

      I am quite new to J2EE and JBoss.

      Using JBuilderX and JBoss 3.2.3 (connected to Oracle), I created a CMP entity bean with a custom finder method.

      Everything deploys fine, but as soon as I make a call to the finder method through my SessionFacade session bean, I get the following exception:

      java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
       java.rmi.ServerException: EJBException:; nested exception is:
       javax.ejb.EJBException: Unknown query: public abstract java.util.Collection kernel.CifCommonHome.findByCustNr(int) throws javax.ejb.FinderException


      I've been hacking through all the source and xml files, but can find absolutely no solution.

      my ejb-jar.xml file:
      <?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>
       <display-name>KernelEJB</display-name>
       <enterprise-beans>
       <entity>
       <display-name>CifCommon</display-name>
       <ejb-name>CifCommon</ejb-name>
       <local-home>kernel.CifCommonHome</local-home>
       <local>kernel.CifCommon</local>
       <ejb-class>kernel.CifCommonBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>kernel.CifCommonPK</prim-key-class>
       <reentrant>False</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>CifCommon</abstract-schema-name>
       <cmp-field>
       <field-name>custNr</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>custShortName</field-name>
       </cmp-field>
       <query>
       <query-method>
       <method-name>findByCustNr</method-name>
       <method-params>
       <method-param>int</method-param>
       </method-params>
       </query-method>
       <ejb-ql>SELECT OBJECT(o) FROM CifCommon o WHERE o.custNr = ?1</ejb-ql>
       </query>
       </entity>
       <session>
       <display-name>CifCommonSessionFacade</display-name>
       <ejb-name>CifCommonSessionFacade</ejb-name>
       <home>kernel.CifCommonSessionFacadeHome</home>
       <remote>kernel.CifCommonSessionFacade</remote>
       <ejb-class>kernel.CifCommonSessionFacadeBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
       <ejb-local-ref>
       <ejb-ref-name>ejb/cifCommon</ejb-ref-name>
       <ejb-ref-type>Entity</ejb-ref-type>
       <local-home>kernel.CifCommonHome</local-home>
       <local>kernel.CifCommon</local>
       <ejb-link>CifCommon</ejb-link>
       </ejb-local-ref>
       </session>
       </enterprise-beans>
       <assembly-descriptor>
       <container-transaction>
       <method>
       <ejb-name>CifCommon</ejb-name>
       <method-name>*</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
       <container-transaction>
       <method>
       <ejb-name>CifCommonSessionFacade</ejb-name>
       <method-name>*</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
       </assembly-descriptor>
      </ejb-jar>



      And my jbosscmp-jdbc.xml file:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
      <jbosscmp-jdbc>
       <defaults>
       <datasource>java:OracleDS</datasource>
       <datasource-mapping>Oracle8</datasource-mapping>
       </defaults>
       <enterprise-beans>
       <entity>
       <ejb-name>CifCommon</ejb-name>
       <datasource>java:OracleDS</datasource>
       <datasource-mapping>Oracle9i</datasource-mapping>
       <table-name>CI.CIF_COMMON</table-name>
       <cmp-field>
       <field-name>custNr</field-name>
       <column-name>CUST_N</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>custShortName</field-name>
       <column-name>CUST_SHORT_NAME</column-name>
       </cmp-field>
       </entity>
       </enterprise-beans>
      </jbosscmp-jdbc>


      Please help as this is driving me up the wall...

      Thanx
      Hendrik

        • 1. Re: Unknown query error on finder method
          sesques

          Hi Hendrik,

          I detect no errors in the descriptors.
          What code causes the exception ?

          Pascal

          • 2. Re: Unknown query error on finder method
            hendrik1

            Hi Pascal

            It happens when the SessionFacade bean calls the entity bean finder method:

            public CifCommonDto[] cifCommonFindByCustNr(int custNr) throws EJBException{
             try{
             return assembleCifCommonDtos(cifCommonHome.findByCustNr(custNr));
             } catch(Exception e){
             throw new EJBException(e.getMessage());
             }
            }
            
            private CifCommonDto[] assembleCifCommonDtos(Collection cifCommons){
             List list = new ArrayList();
             if(cifCommons != null){
             Iterator iterator = cifCommons.iterator();
             while(iterator.hasNext()){
             CifCommon cifCommon = (CifCommon)iterator.next();
             list.add(assembleCifCommonDto(cifCommon));
             }
             }
             CifCommonDto[] returnArray = new CifCommonDto[list.size()];
             return(CifCommonDto[])list.toArray(returnArray);
            }
            


            This is all JBuilderX Code, so I very much doubt that that would cause the error...

            Could it be that I need to change something in JBoss configuration? I include my oracle-ds.xml file as well (just in case)

            <?xml version="1.0" encoding="UTF-8"?>
            <datasources>
             <local-tx-datasource>
             <jndi-name>OracleDS</jndi-name>
            <connection-url>jdbc:oracle:thin:@<my ip>:<my port>:dknl</connection-url>
             <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
             <user-name>test</user-name>
             <password>test</password>
            <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
             </local-tx-datasource>
            </datasources>
            


            • 3. Re: Unknown query error on finder method
              sesques

              Try changing your datasource JNDI name :

              <datasource>java:/OracleDS</datasource>
              

              in jbosscmp-jdbc.xml (you forgot the "/")

              I it work, I don't understand the error, or this error is not the initial one in the log.


              • 4. Re: Unknown query error on finder method
                hendrik1

                Hi Pascal

                Nope, changed it and still got the same error... I attach the complete stack trace.

                SEVERE: RemoteException occurred in server thread; nested exception is:
                 java.rmi.ServerException: EJBException:; nested exception is:
                 javax.ejb.EJBException: Unknown query: public abstract java.util.Collection kernel.CifCommonHome.findByCustNr(int) throws javax.ejb.FinderException
                
                java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
                 java.rmi.ServerException: EJBException:; nested exception is:
                 javax.ejb.EJBException: Unknown query: public abstract java.util.Collection kernel.CifCommonHome.findByCustNr(int) throws javax.ejb.FinderException
                
                 at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
                
                 at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
                
                 at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
                
                 at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
                
                 at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
                
                 at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)
                
                 at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
                
                 at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
                
                 at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:100)
                
                 at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
                
                 at $Proxy1.cifCommonFindByCustNr(Unknown Source)
                
                 at kernel.TestAppClass.btn_find_actionPerformed(TestAppClass.java:85)
                
                 at kernel.TestAppClass_btn_find_actionAdapter.actionPerformed(TestAppClass.java:111)
                
                 at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
                
                 at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
                
                 at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
                
                 at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
                
                 at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
                
                 at java.awt.Component.processMouseEvent(Component.java:5100)
                
                 at java.awt.Component.processEvent(Component.java:4897)
                
                 at java.awt.Container.processEvent(Container.java:1569)
                
                 at java.awt.Component.dispatchEventImpl(Component.java:3615)
                
                 at java.awt.Container.dispatchEventImpl(Container.java:1627)
                
                 at java.awt.Component.dispatchEvent(Component.java:3477)
                
                 at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
                
                 at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
                
                 at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
                
                 at java.awt.Container.dispatchEventImpl(Container.java:1613)
                
                 at java.awt.Window.dispatchEventImpl(Window.java:1606)
                
                 at java.awt.Component.dispatchEvent(Component.java:3477)
                
                 at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
                
                 at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
                
                 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
                
                 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
                
                 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
                
                 at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
                
                Caused by: java.rmi.ServerException: EJBException:; nested exception is:
                 javax.ejb.EJBException: Unknown query: public abstract java.util.Collection kernel.CifCommonHome.findByCustNr(int) throws javax.ejb.FinderException
                
                Caused by: javax.ejb.EJBException: Unknown query: public abstract java.util.Collection kernel.CifCommonHome.findByCustNr(int) throws javax.ejb.FinderException



                • 5. Re: Unknown query error on finder method
                  sesques

                  Hi Hendrik,

                  We had a similar topic this week, quite the same error:
                  http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3833417
                  but your query seems OK, so I don't understand.

                  I think that the error arrives before any database access (and the JNDI name should be the one I give you).
                  There is no error of bad packaging or bad EJB-QL syntax because the server will hangs at deployment time.
                  Is the finder method well declared in your CifCommonHome.java ?
                  Do you try a findByPrimaryKey to validate the correct mapping ?

                  Sorry, no more idea.

                  Pascal

                  • 6. Re: Unknown query error on finder method
                    hendrik1

                    Pascal

                    Yip, double-checked all my interfaces etc. Funny thing is, the findByPrimaryKey gives me exactly the same error. That is why I am starting to wonder if it is not maybe a JBoss configuration that's wrong...

                    Will have a look at the other topic as well.

                    Thanx for your help!

                    • 7. Re: Unknown query error on finder method
                      aloubyansky

                      Are there errors at deployment? Could you post kernel.CifCommonHome?

                      • 8. Re: Unknown query error on finder method
                        ebrain13

                        hi,

                        I think the ejb-ql should look like

                        <ejb-ql>SELECT OBJECT(o) FROM CifCommon AS o WHERE o.custNr = ?1</ejb-ql>

                        You were missing "AS" in the query.

                        HTH

                        Vikram Naik

                        • 9. Re: Unknown query error on finder method
                          sesques

                          No ebrain13,

                          The missing "AS" is supported as well.
                          The solution is elsewhere...

                          Hendrik, as loubyansky says, post your code and your server log.

                          Pascal