1 Reply Latest reply on Aug 5, 2003 11:53 AM by kutter

    simple EJBQL example not working!

    kutter

      Hi, All.
      I am quite confused that even simple EJBQL
      examples are not working.

      Can someone please help me?

      I can as well post the code, but its based on the
      standard Gangster example, all infos below.

      Problem:

      (JBoss 3.2.1-tomcat, CMP Gangster Example of 3.2.1 Documentation)

      I try to use a simple CMP field in an EJB query, and I get a
      "org.jboss.deployment.DeploymentException: Error compiling EJB-QL statement
      'SELECT OBJECT(u) FROM gangster u WHERE u.bestFriend = ?1';
      - nested throwable: (java.lang.NullPointerException)"

      Is it not possible to use CMP fields in EJB queries?

      I did this as close to the JBoss 3.2.1 documentation as possible:
      1) added setter/getter for 'bestFriend' to bean,
      2) added declarations to local interface,
      3) added finderdeclaration to local home
      4) added CMP-field and query-definition of finder to ejb-jar.xml

      My query is SELECT OBJECT(u) FROM gangster u WHERE u.bestFriend = ?1
      and I get the Error compiling EJB-QL statement error.

      What do I wrong?



      Details:
      -------
      I add the getter and setter for a new field bestFriend to the GansterBean.java:
      //new:
      public abstract Gangster getBestFriend();
      public abstract void setBestFriend(Gangster u);

      I add them to the local interface Gangster.java:
      //new:
      Gangster getBestFriend();
      void setBestFriend(Gangster u);

      I add the CMP-field definition to ejb-jar.xml:
      <cmp-field>
      <field-name>bestFriend</field-name>
      </cmp-field>


      I add a new finder to the ejb-jar.xml:

      <query-method>
      <method-name>findBestFriend2</method-name>
      <method-params>
      <method-param>org.jboss.cmp2.crimeportal.Gangster</method-param>
      </method-params>
      </query-method>
      <ejb-ql>[CDATA[
      SELECT OBJECT(u) FROM gangster u WHERE u.bestFriend = ?1
      ]]</ejb-ql>


      I add the corresponding declaration to the local home interface GanagsterHome.java:

      //new:
      Collection findBestFriend2(Gangster g) throws FinderException;

        • 1. SOLVED!
          kutter

          CMP fields pointing to other objects are not
          real relations, one needs to use a 1:1 CMR.

          This leads back to my earlier post that I
          need an example for a 1:1 CMR used in
          EJBQL.

          Best, Philipp