| Summary: | Nested subqueries produce missing conditions between tables. | ||||||
|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Roger Wegmann <roger.wegmann> | ||||
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> | ||||
| Status: | CLOSED FIXED | QA Contact: | |||||
| Severity: | critical | ||||||
| Priority: | P2 | CC: | jamesssss, roger, tom.ware | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
Roger Wegmann
Created attachment 205979 [details]
Maven project that shows the bug.
Does somebody care about reported bugs? 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. Query is,
/* get from all updates with the same name the newest, restricted to all tags (this is only to show the bug) */
updateQuery = entityManager.createQuery(
"SELECT"
+ " u"
+ " FROM"
+ " Update u"
+ " WHERE"
+ " u.timestamp = ("
+ " SELECT"
+ " MAX( uu.timestamp )"
+ " FROM"
+ " Update uu"
+ " JOIN"
+ " uu.tags t"
+ " WHERE"
+ " uu.name = u.name"
+ " AND t.id IN ( SELECT tt.id FROM Tag tt )"
+ " )",
Update.class
);
updates = updateQuery.getResultList();
assertEquals( 2, updates.size() );
/*
Bug: Solution 1) There is a condition like "t0.id = t2.id" missing.
Solution 2) t2 should not be there and t0 should be used instead.
Query generated by Eclipse Link (some brackets are removed):
SELECT
t0.id,
t0.NAME,
t0.TIMESTAMP
FROM
UPDATE t0
WHERE
t0.TIMESTAMP = (
SELECT
MAX(t1.TIMESTAMP)
FROM
TAGS t4,
TAG t3,
UPDATE t2,
UPDATE t1
WHERE
t1.NAME = t2.NAME
AND t3.id IN (
SELECT
t5.id
FROM
TAG t5
)
AND t4.update = t1.id
AND t3.id = t4.tag
)
*/
I could not recreate any issue with this. I assume it was fixed. If you still have issues on the latest build, please re-open the bug. It is also odd, because "= (sub-select)" did not used to be supported (it is now in 2.4). Previous you would need "= ANY(sub-select)", so is odd. Test added, testNestedSubqueries to complex JPQL suite. Also if you use " = ANY ( ... )" it doesn't work. If you try my maven project, you can see the error. And I think there is a difference between returning a wrong result and throwing an exception like "not supported" or something like that. If a query returns a result, I expect either a syntax or not supported exception or a correct result. I still think that this is an important bug. And I can't test 2.4 because it is not yet in the maven repository. Or what is the correct link to the maven repository where I can find the 2.4 version?
updateQuery = entityManager.createQuery(
"SELECT"
+ " u"
+ " FROM"
+ " Update u"
+ " WHERE"
+ " u.timestamp = ANY ("
+ " SELECT"
+ " MAX( uu.timestamp )"
+ " FROM"
+ " Update uu"
+ " JOIN"
+ " uu.tags t"
+ " WHERE"
+ " uu.name = u.name"
+ " AND t.id IN ( SELECT tt.id FROM Tag tt )"
+ " )",
Update.class
);
updates = updateQuery.getResultList();
assertEquals( 2, updates.size() );
Still doesn't work!
What error do you get? Did you try the latest 2.4 build from trunk? This should work with the latest 2.4/trunk build. This was fixed in trunk/2.4, please test on trunk before reopening. The trunk jar can be downloaded from, http://www.eclipse.org/eclipselink/downloads/nightly.php I tested with the trunk (2.4) and I can confirm that it works there. But as long as the version 2.4 is not released, I think it should be fixed also in at least one released version. This is in my opinion a very dangerous bug, because it doesn't throw an exception, it simply returns wrong results. I am sorry, I can also confirm that it works in version 2.3.1 and higher. The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |