7 Replies Latest reply on Mar 4, 2003 2:09 PM by Charles

    JBoss 3.0 Alpha and Custom Finders

    Neal Sanche Newbie

      I've got a custom finder that was working in 2.4.4 and I've recently ported to 3.0.0 Alpha (from CVS) and the finder is now throwing the following error:

      16:11:38,522 ERROR [EntityContainer] invoke returned an exception
      javax.ejb.FinderException: Unknown query: public abstract java.util.Collection com.texar.status.ejb.TaskHome.findUnsubmittedForUser(java.lang.String) throws java.rmi.RemoteException,javax.ejb.FinderException
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.getQueryCommand(JDBCQueryManager.java:50)

      I am using XDoclet 1.1 (also from CVS) to generate the class in question and I've looked at the generated XML for the finders and the following is generated:


      findUnsubmittedForUser
      <![CDATA[USERID = {0} and SUBMITTED = false]]>
      DATE,ID


      Both in the jaws.xml and the jbosscmp-jdbc.xml. I'm stumped as to why this isn't being found by JBoss 3.0Alpha. Any ideas?

        • 1. Re: JBoss 3.0 Alpha and Custom Finders
          marc fleury Master

          I am not familiar with the way to specify finders in the 3.0 package (dain wrote that part) but do we know that the XML that is coming out of XDoclet is indeed correct for the 3.0 version?

          did you buy and read the Dain doco? is this the correct way? if it is not can I ask you to submit a patch for XDoclet to provide the right xml layout.

          thanks

          • 2. Re: JBoss 3.0 Alpha and Custom Finders
            Dain Sundstrom Master

            You are posting to the wrong forum.

            JAWS (CMP 1.1 engine) and JBossCMP (CMP 2 engine) are completely separate implementations and use different specifications for finders. First off JAWS only uses the jaws.xml file and JBossCMP only uses the jbosscmp-jdbc.xml file.

            If are using JAWS, the section in the free docs about finders are still up-to-date. If you are using JBossCMP, the finder specification in the JBossCMP 2.0 docs ($10).

            • 3. Re: JBoss 3.0 Alpha and Custom Finders
              Neal Sanche Newbie

              Alright, alright. If buying the documentation doesn't give me the right information, I'll be back here. Be warned. :)

              -Neal

              • 4. Re: JBoss 3.0 Alpha and Custom Finders
                Neal Sanche Newbie

                Okay, I'm back to say that the documentation did help some. Basically, xdoclet was producing the correct .xml when I told it to use EJB 2.0 spec, and JBoss 3.0. So, no, I wasn't asking the question in the wrong forum, XDoclet is doing it correctly.

                The problem was my syntax. I managed to get the following NullPointerException when attempting to deploy an EJB with a badly formatted EJB-QL query:

                java.lang.NullPointerException
                at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.(JDBCEJBQLQuery.java:51)
                at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createEJBQLQuery(JDBCCommandFactory.java:49)
                at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager.java:177)
                at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:308)
                at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:175)
                at org.jboss.ejb.EntityContainer.start(EntityContainer.java:341)
                at org.jboss.ejb.Application.start(Application.java:219)
                at org.jboss.ejb.ContainerFactory.deploy(ContainerFactory.java:389)
                at org.jboss.ejb.ContainerFactory.deploy(ContainerFactory.java:312)
                at java.lang.reflect.Method.invoke(Native Method)
                at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
                at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                at org.jboss.deployment.J2eeDeployer.startModules(J2eeDeployer.java:468)
                at org.jboss.deployment.J2eeDeployer.startApplication(J2eeDeployer.java:439)
                at org.jboss.deployment.J2eeDeployer.deploy(J2eeDeployer.java:203)
                at java.lang.reflect.Method.invoke(Native Method)
                at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
                at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                at org.jboss.deployment.AutoDeployer.deploy(AutoDeployer.java:681)
                at org.jboss.deployment.AutoDeployer.run(AutoDeployer.java:325)
                at java.lang.Thread.run(Thread.java:484)
                22:12:57,337 ERROR [J2eeDeployer#Default] Starting jbosstest.jar failed!

                The debugging output wasn't much help. I bought the $10 document to find out that all I needed was the EJB2.0 Specification (I'm happy to help with a donation, I'm not being snippy here, honest), and made a XDoclet tag like the following:

                @ejb:finder signature="Collection findContactNeeded(long time)"
                unchecked="true"
                query="SELECT DISTINCT OBJECT(u)
                FROM UARM u
                WHERE u.lastContacted = ?1 AND u.busy = false"
                order="lastContacted ASC"

                I don't think the ordering clause has taken effect. The JBoss log seems to suggest that it'll be using the following SQL:

                2002-01-05 22:36:04,771 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.UARM.findContactNeeded] SQL: SELECT DISTINCT t1_u.siteName FROM uarm t1_u WHERE t1_u.lastContacted = ? AND t1_u.busy = false

                So, now I've got to look up the escape for 'lessthan' and it'll actually be correct for my application, and I'll test it out.

                Why am I so longwinded here? Well, I figure I can stop the trend of 'holding back information' and actually help someone else out who might have the same problems migrating from the old style of using JBoss 2.4, to what needs to be done for JBoss 3.0. I don't think the fact that I use XDoclet to save myself the work of generating .xml files is relevant really. I'm sure others are doing the same.

                -Neal

                • 5. Re: JBoss 3.0 Alpha and Custom Finders
                  Neal Sanche Newbie

                  Just as a final bit of information, I have just finished writing a bit of code to test that custom queries in JBoss 3.0 alpha work from code generated by XDoclet 1.1 (which is currently only available in CVS). I used the following fragment in my ANT script:



















                  The following header on my CMP class:

                  /**
                  * This is the UARM bean where all of the UARM data is stored.
                  *
                  * @ejb:bean name="UARM" type="CMP" jndi-name="usc/UARM" primkey-field="siteName"
                  * @ejb:finder signature="Collection findAll()" unchecked="true"
                  * @ejb:finder signature="Collection findContactNeeded(long time)"
                  * unchecked="true"
                  * query="SELECT OBJECT(u) FROM UARM u WHERE u.lastContacted &lt;= ?1 AND u.busy = false"
                  * order="lastContacted ASC"
                  * @ejb:interface remote-class="org.nsdev.test.ejb.UARM"
                  * @ejb:pk class="java.lang.String" unchecked="true"
                  * @ejb:transaction type="Required"
                  * @ejb:transaction type="Container"
                  *
                  * @jboss:table-name "uarm"
                  * @jboss:create-table "true"
                  * @jboss:remove-table "false"
                  * @jboss:tuned-updates "false"
                  * @jboss:read-only "false"
                  *
                  * @author Neal Sanche
                  */

                  My hat goes off to the XDoclet team, and the implementer of the new custom finder code using the EJB-QL. Nice.

                  -Neal

                  • 6. Re: JBoss 3.0 Alpha and Custom Finders
                    Charles Newbie

                    Greetings -

                    I had the same problem initially (Unknown query) as I'm using JBoss 3.0.4. I've fixed the code so as far as I can tell it should correctly generate the xml for my finder method, but I'm getting the following error when I attempt to deploy. Any suggestions? I've looked at the spec for ejbql, and don't see why it is complaining about the table name.

                    Thanks!

                    Deployment error from JBoss:

                    14:08:25,265 INFO [MainDeployer] Starting deployment of package: file:/C:/Frame
                    works/JBoss/jboss-3.0.4_tomcat-4.1.12/server/default/deploy/ejb-test.jar
                    14:08:25,375 INFO [EjbModule] Creating
                    14:08:25,390 INFO [EjbModule] Deploying TWUserRole
                    14:08:25,406 INFO [EjbModule] Deploying ManageTWUserRole
                    14:08:25,406 INFO [EjbModule] Deploying test/SequenceGenerator
                    14:08:25,437 INFO [EjbModule] Created
                    14:08:25,437 INFO [EjbModule] Starting
                    14:08:30,859 WARN [ServiceController] Problem starting service jboss.j2ee:jndiName=ejb/test/TWUserRoleHome,service=EJB
                    org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "TWUSERROLE" at line 1, column 23.
                    Was expecting one of:
                    "IN" ...
                    &lt;ABSTRACT_SCHEMA&gt; ...
                    )
                    at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.&lt;init&gt;(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:218)
                    at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.startStoreManager(JDBCStoreManager.java:463)

                    ==========================================================

                    Bean code and XDoclet header:

                    /**
                    * This is a user role bean. It is an example of how to use the XDoclet tags.
                    *
                    * @ejb:bean
                    * name="test/TWUserRole"
                    * type="CMP"
                    * jndi-name="ejb/test/TWUserRoleHome"
                    *
                    * @ejb:data-object extends="test.interfaces.AbstractData"
                    * setdata="false"
                    *
                    * @ejb:finder signature="java.util.Collection findUserRolesByUserId(int userId)" unchecked="true" query="SELECT OBJECT(u) FROM TWUSERROLE AS u WHERE u.USER_USERID = ?1"
                    *
                    * @jboss:table-name "TWUSERROLE"
                    * @jboss:create-table "${jboss.create.table}"
                    * @jboss:remove-table "${jboss.remove.table}"
                    * @jboss:tuned-updates "${jboss.tuned.updates}"
                    * @jboss:read-only "${jboss.read.only}"
                    *
                    * @version $Revision: 1.0 $
                    * @author $Author: Charles $
                    *
                    */

                    // Also in my entity bean code:
                    public abstract java.util.Collection findUserRolesByUserId( int userId ) throws FinderException;

                    ==========================================================

                    Output after running ant:

                    ejb-jar.xml:

                    &lt;ejb-class&gt;test.entity.TWUserRoleCMP&lt;/ejb-class&gt;
                    &lt;persistence-type&gt;Container&lt;/persistence-type&gt;
                    &lt;prim-key-class&gt;test.interfaces.TWUserRolePK&lt;/prim-key-class&gt;
                    &lt;reentrant&gt;False&lt;/reentrant&gt;
                    &lt;cmp-version&gt;2.x&lt;/cmp-version&gt;
                    &lt;abstract-schema-name&gt;test/TWUserRole&lt;/abstract-schema-name&gt;
                    &lt;cmp-field &gt;
                    &lt;description&gt;&lt;![CDATA[Retrieve the TestEntity's Name.]]&gt;&lt;/description&gt;
                    &lt;field-name&gt;name&lt;/field-name&gt;
                    &lt;/cmp-field&gt;
                    &lt;cmp-field &gt;
                    &lt;description&gt;&lt;![CDATA[Retrieve the TestEntity's id.]]&gt;&lt;/description&gt;
                    &lt;field-name&gt;id&lt;/field-name&gt;
                    &lt;/cmp-field&gt;

                    &lt;query&gt;
                    &lt;query-method&gt;
                    &lt;method-name&gt;findUserRolesByUserId&lt;/method-name&gt;
                    &lt;method-params&gt;
                    &lt;method-param&gt;int&lt;/method-param&gt;
                    &lt;/method-params&gt;
                    &lt;/query-method&gt;
                    &lt;ejb-ql&gt;&lt;![CDATA[SELECT OBJECT(u) FROM TWUSERROLE AS u WHERE u.USER_USERID = ?1]]&gt;&lt;/ejb-ql&gt;
                    &lt;/query&gt;

                    • 7. Re: JBoss 3.0 Alpha and Custom Finders
                      Charles Newbie

                      (This is take two - didn't see my reply after first submittal)

                      Greetings -

                      I had the same problem initially (Unknown query) as I'm using JBoss 3.0.4. I've fixed the code so as far as I can tell it should correctly generate the xml for my finder method, but I'm getting the following error when I attempt to deploy. Any suggestions? I've looked at the spec for ejbql, and don't see why it is complaining about the table name.

                      Thanks!

                      Deployment error from JBoss:

                      14:08:25,265 INFO [MainDeployer] Starting deployment of package: file:/C:/Frame
                      works/JBoss/jboss-3.0.4_tomcat-4.1.12/server/default/deploy/ejb-test.jar
                      14:08:25,375 INFO [EjbModule] Creating
                      14:08:25,390 INFO [EjbModule] Deploying TWUserRole
                      14:08:25,406 INFO [EjbModule] Deploying ManageTWUserRole
                      14:08:25,406 INFO [EjbModule] Deploying test/SequenceGenerator
                      14:08:25,437 INFO [EjbModule] Created
                      14:08:25,437 INFO [EjbModule] Starting
                      14:08:30,859 WARN [ServiceController] Problem starting service jboss.j2ee:jndiName=ejb/test/TWUserRoleHome,service=EJB
                      org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "TWUSERROLE" at line 1, column 23.
                      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:218)
                      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.startStoreManager(JDBCStoreManager.java:463)

                      ==========================================================

                      Bean code and XDoclet header:

                      /**
                      * This is a user role bean. It is an example of how to use the XDoclet tags.
                      *
                      * @ejb:bean
                      * name="test/TWUserRole"
                      * type="CMP"
                      * jndi-name="ejb/test/TWUserRoleHome"
                      *
                      * @ejb:data-object extends="test.interfaces.AbstractData"
                      * setdata="false"
                      *
                      * @ejb:finder signature="java.util.Collection findUserRolesByUserId(int userId)" unchecked="true" query="SELECT OBJECT(u) FROM TWUSERROLE AS u WHERE u.USER_USERID = ?1"
                      *
                      * @jboss:table-name "TWUSERROLE"
                      * @jboss:create-table "${jboss.create.table}"
                      * @jboss:remove-table "${jboss.remove.table}"
                      * @jboss:tuned-updates "${jboss.tuned.updates}"
                      * @jboss:read-only "${jboss.read.only}"
                      *
                      * @version $Revision: 1.0 $
                      * @author $Author: Charles $
                      *
                      */

                      // Also in my entity bean code:
                      public abstract java.util.Collection findUserRolesByUserId( int userId ) throws FinderException;

                      ==========================================================

                      Output after running ant:

                      ejb-jar.xml:

                      <ejb-class>test.entity.TWUserRoleCMP</ejb-class>
                      <persistence-type>Container</persistence-type>
                      <prim-key-class>test.interfaces.TWUserRolePK</prim-key-class>
                      False
                      <cmp-version>2.x</cmp-version>
                      <abstract-schema-name>test/TWUserRole</abstract-schema-name>
                      <cmp-field >
                      <![CDATA[Retrieve the TestEntity's Name.]]>
                      <field-name>name</field-name>
                      </cmp-field>
                      <cmp-field >
                      <![CDATA[Retrieve the TestEntity's id.]]>
                      <field-name>id</field-name>
                      </cmp-field>


                      <query-method>
                      <method-name>findUserRolesByUserId</method-name>
                      <method-params>
                      <method-param>int</method-param>
                      </method-params>
                      </query-method>
                      <ejb-ql><![CDATA[SELECT OBJECT(u) FROM TWUSERROLE AS u WHERE u.USER_USERID = ?1]]></ejb-ql>