Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 355186

Summary: Unnecessary Table Join in Native Many-to-Many Query generated from JPQL
Product: z_Archived Reporter: Bernard Missing name <bht237>
Component: EclipselinkAssignee: Project Inbox <eclipselink.orm-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P2 CC: tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
Testcase none

Description Bernard Missing name CLA 2011-08-19 01:25:36 EDT
Build Identifier: 2.3.0.v20110604-r9504

The JPQL query

select
    object(emp)
from
    Employee emp
where
    emp.illnesses is empty

creates a a native query that joins the table illness which is not good.

The generated SQL is:

SELECT
    t0.ID
    , t0.NAME
FROM
    EMPLOYEE t0
WHERE (
          (
    SELECT
        COUNT(t1.ID) -- should be count(t2.employee_id)
    FROM
        employee_illness t2
        , ILLNESS t1 -- ############ unnecessary inner join
    WHERE (
            (
        t2.employee_id = t0.ID
             )
        AND (
            t1.ID = t2.illness_id -- ############# unnecessary inner join
            )
           )
          )
       = ?
      )
bind => [0]


Reproducible: Always

Steps to Reproduce:
Please refer to the attached testcase.
Comment 1 Bernard Missing name CLA 2011-08-19 01:27:04 EDT
Created attachment 201765 [details]
Testcase
Comment 2 Tom Ware CLA 2011-09-09 09:02:56 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:04:35 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink