IBM Support

PM06925: A JPQL QUERY WHICH CONTAINS A COMPOUND PRIMARY KEY ONLY USES ONE OF THE PRIMARY KEYS

Fixes are available

7.0.0.13: WebSphere Application Server V7.0 Fix Pack 13 for AIX
7.0.0.13: WebSphere Application Server V7.0 Fix Pack 13 for HP-UX
7.0.0.13: WebSphere Application Server V7.0 Fix Pack 13 for IBM i
7.0.0.13: WebSphere Application Server V7.0 Fix Pack 13 for Linux
7.0.0.13: WebSphere Application Server V7.0 Fix Pack 13 for Solaris
7.0.0.13: WebSphere Application Server V7.0 Fix Pack 13 for Windows
7.0.0.13: Java SDK 1.6 SR8FP1 Cumulative Fix for WebSphere Application Server
7.0.0.15: WebSphere Application Server V7.0 Fix Pack 15 for AIX
7.0.0.15: Java SDK 1.6 SR9 Cumulative Fix for WebSphere Application Server
7.0.0.15: WebSphere Application Server V7.0 Fix Pack 15 for HP-UX
7.0.0.15: WebSphere Application Server V7.0 Fix Pack 15 for IBM i
7.0.0.15: WebSphere Application Server V7.0 Fix Pack 15 for Linux
7.0.0.15: WebSphere Application Server V7.0 Fix Pack 15 for Solaris
7.0.0.15: WebSphere Application Server V7.0 Fix Pack 15 for Windows
7.0.0.17: WebSphere Application Server V7.0 Fix Pack 17
7.0.0.17: Java SDK 1.6 SR9 FP1 Cumulative Fix for WebSphere Application Server
7.0.0.19: WebSphere Application Server V7.0 Fix Pack 19
7.0.0.21: WebSphere Application Server V7.0 Fix Pack 21
7.0.0.23: WebSphere Application Server V7.0 Fix Pack 23
7.0.0.25: WebSphere Application Server V7.0 Fix Pack 25
7.0.0.27: WebSphere Application Server V7.0 Fix Pack 27
7.0.0.29: WebSphere Application Server V7.0 Fix Pack 29
7.0.0.31: WebSphere Application Server V7.0 Fix Pack 31
7.0.0.27: Java SDK 1.6 SR13 FP2 Cumulative Fix for WebSphere Application Server
7.0.0.33: WebSphere Application Server V7.0 Fix Pack 33
7.0.0.35: WebSphere Application Server V7.0 Fix Pack 35
7.0.0.37: WebSphere Application Server V7.0 Fix Pack 37
7.0.0.39: WebSphere Application Server V7.0 Fix Pack 39
7.0.0.41: WebSphere Application Server V7.0 Fix Pack 41
7.0.0.43: WebSphere Application Server V7.0 Fix Pack 43
7.0.0.45: WebSphere Application Server V7.0 Fix Pack 45
7.0.0.19: Java SDK 1.6 SR9 FP2 Cumulative Fix for WebSphere Application Server
7.0.0.21: Java SDK 1.6 SR9 FP2 Cumulative Fix for WebSphere
7.0.0.23: Java SDK 1.6 SR10 FP1 Cumulative Fix for WebSphere
7.0.0.25: Java SDK 1.6 SR11 Cumulative Fix for WebSphere Application Server
7.0.0.27: Java SDK 1.6 SR12 Cumulative Fix for WebSphere Application Server
7.0.0.29: Java SDK 1.6 SR13 FP2 Cumulative Fix for WebSphere Application Server
7.0.0.45: Java SDK 1.6 SR16 FP60 Cumulative Fix for WebSphere Application Server
7.0.0.31: Java SDK 1.6 SR15 Cumulative Fix for WebSphere Application Server
7.0.0.35: Java SDK 1.6 SR16 FP1 Cumulative Fix for WebSphere Application Server
7.0.0.37: Java SDK 1.6 SR16 FP3 Cumulative Fix for WebSphere Application Server
7.0.0.39: Java SDK 1.6 SR16 FP7 Cumulative Fix for WebSphere Application Server
7.0.0.41: Java SDK 1.6 SR16 FP20 Cumulative Fix for WebSphere Application Server
7.0.0.43: Java SDK 1.6 SR16 FP41 Cumulative Fix for WebSphere Application Server

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • The following two JPQL queries are being issued:
    
    1) query = "SELECT COUNT (DISTINCT e) FROM G2 e";
    2) query = "SELECT COUNT (DISTINCT f1.g2) FROM F1 f1";
    
    Where G2 contains a compound primary key (namely PK1 and
    PK2), and F1 has a @ManyToOne relationship with G2.
    
    These queries yield an incorrect count because the SQL is not
    generated properly for the case where a compound primary key is
    used.
    

Local fix

Problem summary

  • ****************************************************************
    * USERS AFFECTED:  All users of IBM ‚ ® WebSphere ‚ ® Applicatio
    *                  Server V7.0.0 who make use of JPQL queries  *
    *                  which contain the COUNT function and        *
    *                  compound primary keys.                      *
    ****************************************************************
    * PROBLEM DESCRIPTION: Count(Distinct e) in JPQL gives the     *
    *                      wrong result when the id field is a     *
    *                      compound primary key.                   *
    ****************************************************************
    * RECOMMENDATION:                                              *
    ****************************************************************
    The following two JPQL queries are being issued:
    
    1) query = "SELECT COUNT (DISTINCT e) FROM G2 e";
    2) query = "SELECT COUNT (DISTINCT f1.g2) FROM F1 f1";
    
    Where G2 contains a compound primary key (namely PK1 and PK2),
    and F1 has a @ManyToOne relationship with G2.
    
    For the first query, the goal is to count all distinct G2.
    However, this JPQL query results in an SQL as follows:
    
    SELECT COUNT(DISTINCT t0.PK1) FROM G2 t0  optimize for 1 row
    
    This is a problem because the SQL only takes into account the
    primary key PK1, however, it should also use primary key PK2.
    
    For the second query, the goal is to count the distinct G2
    referenced by F1.  However, this JPQL query results in an SQL
    as follows:
    
    SELECT COUNT(DISTINCT t1.PK1) FROM F1 t0 INNER JOIN G2 t1 ON
    t0.PK1 = t1.PK1 AND t0.PK2 = t1.PK2  optimize for 1 row
    
    Again, this is wrong because PK2 is not taken into account.
    Things are further complicated with this query given relation
    navigation is being used.  That is, the query attempts to find
    all distict G2 referenced by F1.
    

Problem conclusion

  • For the first query, code has been added to handle the case
    where a compound primary key is used in a 'COUNT( DISTINCT )'.
    To enable this code, a user must set the following openJPA
    property in their persistence.xml file:
    
    <property name="openjpa.jdbc.DBDictionary"
    value="useWildCardForCount=true"/>
    
    
    For the second query, the property of 'useWildCardForCount'
    will not generate correct sql with the right result given
    relation navigation is involved.  With this fix, limited
    support for count(distinct compound key) will be supported
    when count(compound primary key) appears in the projection
    list. This projection list will have only one projection item,
    that is, count, in it. OpenJPA will generate the following SQL:
    
    (1)
    String jpql = "SELECT COUNT (DISTINCT e) FROM G2 e";
    generated SQL:
    SELECT COUNT(*) FROM G2 t0
    
    (2)
    String jpql = "SELECT COUNT (DISTINCT f1.g2) FROM F1 f1";
    generated SQL:
    SELECT COUNT(*) FROM (SELECT DISTINCT G1.G1PK, G1.G2PK FROM F1
    t0 INNER JOIN G2 t1 ON t0.G1PK = t1.G1PK AND t0.G2PK = t1.G2PK)
    
    An UnsupportedException will be thrown in all other situations.
    
    The fix for this APAR is currently targeted for inclusion
    in Fix Pack 7.0.0.13 of WebSphere Application Server
    version 7.0.0.  Please refer to the Recommended Updates
    page for delivery information:
    http://www.ibm.com/support/docview.wss?rs=180&uid=swg27004980
    

Temporary fix

Comments

APAR Information

  • APAR number

    PM06925

  • Reported component name

    WEBS APP SERV N

  • Reported component ID

    5724H8800

  • Reported release

    700

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2010-02-05

  • Closed date

    2010-05-06

  • Last modified date

    2010-07-19

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    WEBS APP SERV N

  • Fixed component ID

    5724H8800

Applicable component levels

  • R700 PSY

       UP

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7.0","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
25 October 2021