Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368544 - wrong sql is generated when using coalesce on tables left outer joined to a selection
Summary: wrong sql is generated when using coalesce on tables left outer joined to a s...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 major with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-13 08:25 EST by Attila Czabany CLA
Modified: 2022-06-09 10:21 EDT (History)
2 users (show)

See Also:


Attachments
maven project to reproduce the bug (10.79 KB, application/x-zip-compressed)
2012-01-13 08:26 EST, Attila Czabany CLA
no flags Details
attached test maven project table diagram (42.42 KB, image/jpeg)
2012-01-13 08:33 EST, Attila Czabany CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Attila Czabany CLA 2012-01-13 08:25:31 EST
Build Identifier: org.eclipse.persistence 2.3.1-M8


If coalesce is used on a single table (eg. for localization) then the resulting sql query is correct.
However, if the coalesce is used on a table that is joined to an other table, then the sql is incorrect.

Here is the example of an sql that is generated:

SELECT 
	t0.DVD_DATA_ID, 
	COALESCE(
		(SELECT t3.LOC_VALUE FROM DVD_CASING t5 LEFT OUTER JOIN TEST_DVD_DATA t4 ON (t4.DVD_DATA_ID = t5.DVD), TEST_LOCALIZED_DATA t3 WHERE ((t3.LOC_KEY = t4.FILM_NAME) AND (t3.LOC_LOCALE = 'hu'))),
		(SELECT t6.LOC_VALUE FROM TEST_LOCALIZED_DATA t6 WHERE ((t6.LOC_KEY = t4.FILM_NAME) AND (t6.LOC_LOCALE = 'en'))),
		t0.FILM_NAME ), 
	COALESCE(
		(SELECT t7.LOC_VALUE FROM TEST_DVD_DATA t4 LEFT OUTER JOIN TEST_DVD_PROPERTY t8 ON (t8.DVD = t4.DVD_DATA_ID), TEST_LOCALIZED_DATA t7 WHERE ((t7.LOC_KEY = t8.PROPERTY_NAME) AND (t7.LOC_LOCALE = 'hu'))),
		(SELECT t9.LOC_VALUE FROM TEST_LOCALIZED_DATA t9 WHERE ((t9.LOC_KEY = t8.PROPERTY_NAME) AND (t9.LOC_LOCALE = 'en'))),
		t2.PROPERTY_NAME ), 
	COALESCE(
		(SELECT t10.LOC_VALUE FROM TEST_LOCALIZED_DATA t10 WHERE ((t10.LOC_KEY = t1.CASING_TITLE) AND (t10.LOC_LOCALE = 'hu'))),
		(SELECT t11.LOC_VALUE FROM TEST_LOCALIZED_DATA t11 WHERE ((t11.LOC_KEY = t1.CASING_TITLE) AND (t11.LOC_LOCALE = 'en'))),
		t1.CASING_TITLE ) 
FROM DVD_CASING t1 LEFT OUTER JOIN TEST_DVD_DATA t0 ON (t0.DVD_DATA_ID = t1.DVD) LEFT OUTER JOIN TEST_DVD_PROPERTY t2 ON (t2.DVD = t0.DVD_DATA_ID) 
ORDER BY t0.FILM_NAME ASC

The problems are in the first two coalesces, the third is OK. 
For example instead of 
SELECT t9.LOC_VALUE FROM TEST_LOCALIZED_DATA t9 WHERE ((t9.LOC_KEY = t8.PROPERTY_NAME) AND (t9.LOC_LOCALE = 'en'))

SELECT t9.LOC_VALUE FROM TEST_LOCALIZED_DATA t9 WHERE ((t9.LOC_KEY = t2.PROPERTY_NAME) AND (t9.LOC_LOCALE = 'en')) should be used, to reference the outermost table that is relevant, and not the table that is in the FROM section in on the previous coalesce tag.

You find a maven project attached to reproduce this bug.

Reproducible: Always

Steps to Reproduce:
use coalesce on any attribute of a left joined entity
Comment 1 Attila Czabany CLA 2012-01-13 08:26:44 EST
Created attachment 209451 [details]
maven project to reproduce the bug
Comment 2 Attila Czabany CLA 2012-01-13 08:33:14 EST
Created attachment 209452 [details]
attached test maven project table diagram
Comment 3 Tom Ware CLA 2012-02-09 10:28:38 EST
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 4 Eclipse Webmaster CLA 2022-06-09 10:21:16 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink