Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-1727

Incorrect empty result collection from finder method

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Major
    • No Release
    • JBossAS-4.0.1 SP1
    • CMP service
    • None

    Description

      EJB finder method fails when the WHERE condition is an equality test on the BIGINT primary key of a single valued related object (container managed relationship).

      Something must be wrong in the query/comparison engine, because the same scenario for a VARCHAR typed field works and refactoring the EJBQL from equality test to BETWEEN <value> AND <samevalue> is also working:

      Entity 'department' has a relationship to 'division'. We want to find all departments that belong to a special division (known by it's primary key 'Id'). Note: we intentionally don't use the multi-valued CMR-Collection of the 'division' entity, because we want to apply additional filtering criteria, and the CMR-query cannot be customized/augmented.

      Database Schema for the objects:
      mysql> desc Division;
      -----------------------------------------------------+

      Field Type Null Key Default Extra

      -----------------------------------------------------+

      Id bigint(20)   PRI NULL auto_increment
      VisibleName varchar(255) YES   NULL  
      Deleted tinyint(4)     0  
      Code varchar(255)        
      Label varchar(255)        

      -----------------------------------------------------+
      5 rows in set (0.00 sec)

      mysql> desc Department;
      -----------------------------------------------------+

      Field Type Null Key Default Extra

      -----------------------------------------------------+

      Id bigint(20)   PRI NULL auto_increment
      VisibleName varchar(255) YES   NULL  
      Deleted tinyint(4)     0  
      Code varchar(255)        
      Label varchar(255)        
      fk_Division bigint(20) YES   NULL  

      -----------------------------------------------------+
      6 rows in set (0.00 sec)

      The following query returns a WRONG (empty) result collection:

      <query>
      <query-method>
      <method-name>findByDivisionId2</method-name>
      <method-params>
      <method-param>java.lang.Long</method-param>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT DISTINCT OBJECT(o) FROM Department AS o
      WHERE o.rp_Division.p_Id = ?1 ORDER BY o.p_Code]]></ejb-ql>
      </query>

      Tracing JBoss CMP logs and extracting generated SQL statement, placeholder '?' replaced by actual parameter:
      SELECT DISTINCT t0_o.Id, t0_o.Code
      FROM Department t0_o, Division t1_o_rp_Division
      WHERE (t1_o_rp_Division.Id = 70900551572717569 AND t0_o.fk_Division=t1_o_rp_Division.Id)
      ORDER BY t0_o.Code ASC

      Id Code
      70900666037501953 FB 10
      70900670665850882 FB 11
      ...

      This gives (on the database level) the correct result! Even though JBoss pops up with an empty collection.

      The following query works, difference is that we are using a String argument for comparison:

      <query>
      <query-method>
      <method-name>findByDivisionCode</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT DISTINCT OBJECT(o) FROM Department AS o
      WHERE o.rp_Division.p_Code = ?1 ORDER BY o.p_Code]]></ejb-ql>
      </query>

      The following EJBQL query works as a work-around, even though it should be identical to the above one:

      <query>
      <query-method>
      <method-name>findByDivisionId</method-name>
      <method-params>
      <method-param>java.lang.Long</method-param>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT DISTINCT OBJECT(o) FROM Department AS o
      WHERE o.rp_Division.p_Id BETWEEN ?1 AND ?1 ORDER BY o.p_Code]]></ejb-ql>
      </query>

      How can that be, that comparison with '= 12345' fails and 'BETWEEN 123455 AND 12345' works ?

      Attachments

        Activity

          People

            olubyans@redhat.com Alexey Loubyansky
            hofmalex Frank Hofmann (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: