Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 318314 - Inheritance strategy JOINED + composite primary key = duplicate names in JOIN
Summary: Inheritance strategy JOINED + composite primary key = duplicate names in JOIN
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-29 09:28 EDT by klaus.friedel CLA
Modified: 2022-06-09 10:27 EDT (History)
4 users (show)

See Also:


Attachments
Code to reproduce the bug (610.96 KB, application/x-zip-compressed)
2010-07-12 05:27 EDT, klaus.friedel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description klaus.friedel CLA 2010-06-29 09:28:42 EDT
Using inheritance strategy "JOINED" on entities with composite primary keys produces wrong SQL for some queries.

The produced SQL may contain duplicate names.

This diff fixes the bug:

Index: org/eclipse/persistence/descriptors/InheritancePolicy.java
===================================================================
--- org/eclipse/persistence/descriptors/InheritancePolicy.java	(revision )
+++ org/eclipse/persistence/descriptors/InheritancePolicy.java	(revision )
@@ -132,8 +132,13 @@
            // allTables should've been null, too
            allTables = new Vector(getDescriptor().getTables());
         }
+        //Bugfix: Prevent duplicate names in JOIN
+        if(! childrenTables.contains(table)){
-        childrenTables.add(table);
+            childrenTables.add(table);
+        }
+        if(! allTables.contains(table)){
-        allTables.add(table);
+            allTables.add(table);
+        }
         childrenTablesJoinExpressions.put(table, expression);
         childrenJoinExpression = expression.and(childrenJoinExpression);
     }
Comment 1 klaus.friedel CLA 2010-06-29 09:29:36 EDT
Same bug in Eclipselink 2.0.2
Comment 2 Gordon Yorke CLA 2010-06-29 15:33:55 EDT
Can you please provide an example query and the resulting SQL?
Comment 3 klaus.friedel CLA 2010-07-12 05:10:13 EDT
The attached test code executes:

JPQL:
em.createQuery("select h from HerkunftDetail h where h.zuordnungsmerkmal='A'")
            .setHint(QueryHints.LEFT_FETCH, "h.vorgang")
            .getResultList();




The resulting SQL:

SELECT
t5.ID,
t5.LEISTUNGSEMPFAENGER,
t5.ZUORDNUNGSMERKMAL,
t5.DETAILID,
t5.BUCHUNGSKONTO,
t5.VORGANG_ID,
t0.ID,
t0.LEISTUNGSEMPFAENGER,
t0.DTYPE,
t0.LEISTUNGSINANSPRUCHNAHMEBIS,
t0.LEISTUNGSINANSPRUCHNAHMEVON,
t1.ID,
t1.LEISTUNGSEMPFAENGER,
t1.AUFANFORDERUNG,
t3.ID,
t3.LEISTUNGSEMPFAENGER,
t3.EXTERNEREFERENZ
FROM HerkunftDetailX t5
LEFT OUTER JOIN (LeistungsvorgangX t0 
LEFT OUTER JOIN LeistungsantragX t1 ON (t1.LEISTUNGSEMPFAENGER = t0.LEISTUNGSEMPFAENGER) 
LEFT OUTER JOIN LeistungsantragX t1 ON (t1.LEISTUNGSEMPFAENGER = t0.LEISTUNGSEMPFAENGER) 
LEFT OUTER JOIN LeistungsfallX t3 ON (t3.LEISTUNGSEMPFAENGER = t0.LEISTUNGSEMPFAENGER) 
LEFT OUTER JOIN LeistungsfallX t3 ON (t3.LEISTUNGSEMPFAENGER = t0.LEISTUNGSEMPFAENGER)) ON ((t0.id = t5.VORGANG_ID) AND (t0.leistungsempfaenger = t5.LEISTUNGSEMPFAENGER)),
LeistungsfallX t4,
LeistungsantragX t2
WHERE (t5.ZUORDNUNGSMERKMAL = ?)
Comment 4 klaus.friedel CLA 2010-07-12 05:27:38 EDT
Created attachment 174000 [details]
Code to reproduce the bug
Comment 5 James Sutherland CLA 2010-07-14 15:05:58 EDT
I think this was fixed in 2.1, was the latest version tried?
Comment 6 klaus.friedel CLA 2010-07-15 04:18:20 EDT
(In reply to comment #5)
> I think this was fixed in 2.1, was the latest version tried?

Last version checked: 2.0.2

I tested again with 2.1 and can confirm that the bug is fixed.

Will we see a backport for 1.2 ?
Comment 7 Tom Ware CLA 2010-08-17 13:43:45 EDT
Setting to fixed based on above comments.

Currently there are no plans to backport to 1.2.  There has been a major release and several minor releases since 1.2 and the inclusion list for the next 1.2 patch is intentionally very limited.
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:27:51 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink