2 Replies Latest reply on Oct 24, 2002 11:00 AM by alexis

    JBOSS CMP creates empty SELECT

    alexis

      Hi all,


      One of my Entity bean is unable to create a valid SQL query when it call a Finder.


      When I call findByAppIDAndItemID, JBoss fails to execute the query:
      14:25:08,273 DEBUG [findByAppIDAndItemID] Executing SQL: SELECT FROM rating t0_r WHERE t0_r.appID = ? AND t0_r.itemID = ?
      14:25:08,403 DEBUG [findByAppIDAndItemID] Find failed
      java.sql.SQLException: Syntax error or access violation: You have an error in your SQL syntax near 'FROM rating t0_r WHERE t0_r.appID = 1 AND t0_r.itemID = 130' at line 1
      at org.gjt.mm.mysql.MysqlIO.sendCommand(Unknown Source)
      at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(Unknown Source)
      .....


      Why is there nothing between SELECT and FROM?

      This is very curious because the ejbSelect below, which is nearly a copy of the Finder, works fine. It seems this bean can not use finders. But all of my other beans can. Can someone help to fix this strange issue?


      Here is my Entity bean into ejb-jar.xml:

      <ejb-name>Rating</ejb-name>
      nix.prj.eovia.ejb.RatingHome
      nix.prj.eovia.ejb.Rating
      <local-home>nix.prj.eovia.ejb.RatingLocalHome</local-home>
      nix.prj.eovia.ejb.RatingLocal
      <ejb-class>nix.prj.eovia.ejb.RatingBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      <prim-field>ratingID</prim-field>
      False

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>rating</abstract-schema-name>
      <cmp-field>
      <field-name>ratingID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>appID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>itemID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>rating</field-name>
      </cmp-field>


      <query-method>
      <method-name>findByAppIDAndItemID</method-name>
      <method-params>
      <method-param>int</method-param>
      <method-param>int</method-param>
      </method-params>
      </query-method>
      <result-type-mapping>Local</result-type-mapping>
      <ejb-ql>SELECT OBJECT(r) FROM rating r WHERE r.appID=?1 AND r.itemID=?2</ejb-ql>



      <query-method>
      <method-name>ejbSelectRatingsByAppIDAndItemID</method-name>
      <method-params>
      <method-param>int</method-param>
      <method-param>int</method-param>
      </method-params>
      </query-method>
      <result-type-mapping>Local</result-type-mapping>
      <ejb-ql>SELECT r.rating FROM rating r WHERE r.appID=?1 AND r.itemID=?2</ejb-ql>



      I'm runnig JBoss 3.0.3 over MySQL 3.23.51-Max using InnoDB tables.


      Thanks,
      Alexis

        • 1. Re: JBOSS CMP creates empty SELECT
          alexis

          Hi all,

          I have a litte more info about this issue. I have downloaded JBoss 3.0.3 sources. thus I can debug my bean and watch inside JBoos to understand what's happening.

          At deployment, JBoss does not understand that ratingID is my primary key. In org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.java:

          if(cmpField.isPrimaryKeyMember()) {
          primaryKeyFields.add(cmpField);
          } else {
          cmpFields.add(cmpField);
          }

          cmpField.isPrimaryKeyMember() return false instead of true. Then ratingID is not stored as primary key and SELECT query as findByPrimaryKey can not be build correctly.

          But all my other bean primary keys in the same ejb-jar work fine. Why rating does not, this is very strange.

          Can anybody help me?

          Thanks,
          Alexis

          • 2. Got it!
            alexis

            I made a mistake into ejb-jar.xml. I wrote <prim-field>ratingID</prim-field> instead of <primkey-field>ratingID</primkey-field>

            But it so sad that the XML parser do not throw a error.

            I hope this post will help someone later.

            Alexis