Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 300625 - Unnecessary Table Join in Native Query generated from JPQL
Summary: Unnecessary Table Join in Native Query generated from JPQL
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-24 18:45 EST by Bernard Missing name CLA
Modified: 2022-06-09 10:31 EDT (History)
3 users (show)

See Also:


Attachments
NetBeans project in zip file (14.15 KB, application/octet-stream)
2010-01-24 18:47 EST, Bernard Missing name CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bernard Missing name CLA 2010-01-24 18:45:58 EST
Build Identifier: 2.0.0.v20091127-r5931

version: Eclipse Persistence Services - 2.0.0.v20091127-r5931

A rather simple JPQL query produces an unnecessary table join.
Please refer to the attached testcase (NetBeans project).

The generated native SQL is:

SELECT
    t0.ID
    , t0.PROVIDERID
FROM
    TRIP t0
WHERE t0.PROVIDERID NOT IN (
    SELECT
        t1.PROVIDERID
    FROM
        TRIP t2
        , TRIPEXCLUDE t1
    WHERE (
        (
            (
                (t1.PROVIDERID = t2.PROVIDERID) AND (t1.SEARCHERID = ?)
            )
            AND (t1.SERVICEID = ?)
        )
        AND (t0.ID = t2.ID)
    )
)

The SQL should be as follows (not including table t2):

SELECT
    t0.ID
    , t0.PROVIDERID
FROM
    TRIP t0
WHERE t0.PROVIDERID NOT IN (
    SELECT
        t1.PROVIDERID
    FROM
        TRIPEXCLUDE t1
    WHERE (
        (
            (
                (t1.SEARCHERID = ?)
            )
            AND (t1.SERVICEID = ?)
        )
    )
)


Reproducible: Always

Steps to Reproduce:
Please refer to attached testcase
Comment 1 Bernard Missing name CLA 2010-01-24 18:47:37 EST
Created attachment 157068 [details]
NetBeans project in zip file
Comment 2 Tom Ware CLA 2010-02-08 09:31:25 EST
Setting target and priority.  See the following page for details of what those values mean: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 3 James Sutherland CLA 2011-11-07 14:34:15 EST
The query is, 

"select object(t) from Trip t where t.providerId not in(
select tex.providerId from TripExclude tex where tex.providerId = t.providerId and tex.searcherId = :memberId and tex.serviceId = :serviceId)"
Comment 4 James Sutherland CLA 2011-11-07 14:41:30 EST
This was fixed.

Verified that it no longer occurs in 2.4.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:31:32 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink