Eclipselink 2.6.4 LEFT JOIN TREAT QUERY Not working properly [message #1749385] |
Tue, 06 December 2016 02:38  |
Eclipse User |
|
|
|
Hi.
I have detected that the "TREAT" feature in eclipse link 2.6.4 seems not to be working properly, at least in respect to left join queries.
Right now I do not have a sample application that I can provide you but I can summarize the behavior.
On upgrade from JEE 6 to JEE 7 library versions and moving to eclipselink 2.6.4 from the 2.4.x, the following behavior was found.
A Query of the from:
SELECT A
FROM Entity a
LEFT JOIN TREAT(a.parent AS B) b
The query does not return any results when our related entity "B" is null.
This is of course not correct behavior because we are doing a LEFT JOIN.
So if a.Parent is null but a exists, we want results to come out.
The reason why such as query in eclipselink 2.6.4 does not work is because, when you look at the NativeSQL of the produced query, a predicate of the following is in the query:
AND
(
-- this is our @DiscriminatorValue("B")
t10.CLASS_TYPE = 'CLASSIFIER_OF_TYPE_B'
)
In order for the LEFT JOIN to be logical correct, the TREAT should not have induced the injection of:
b.CLASS_TYPE = @DiscriminatorValue("B")
but instead it should have injected as predicates into the native SQL something of the form:
b.CLASS_TYPE = @DiscriminatorValue("B")
OR b.CLASS_TYPE IS NULL.
In the LEFT JOIN scenario.
I have compared with the Native sql of the Older eclipse link version 2.4.x.
There, the predicate simply was not added.
In both implementations the compilation into Native SQL was not logically correct, but in the 2.6.4 this change in behavior is causing many queries to break.
Please let me know if a Sample application for this is absolutely needed, if so I will make one.
But I am confident that the people that know of JPQL to NATIVE SQL compilation can figure out if this bug is true or not in a few minutes.
So I doubt there is any need to provide a sample application for this.
Kind regards.
[Updated on: Tue, 06 December 2016 02:41] by Moderator
|
|
|
|
|
Re: Eclipselink 2.6.4 LEFT JOIN TREAT QUERY Not working properly [message #1755692 is a reply to message #1755222] |
Mon, 06 March 2017 15:13  |
Eclipse User |
|
|
|
Treat as specified in the JPA spec states: "If during query execution the first argument to the TREAT operator is not a subtype (proper or
improper) of the target type, the path is considered to have no value, and does not participate in the
determination of the result. That is, in the case of a join, the referenced object does not participate in the
result, and in the case of a restriction, the associated predicate is false. Use of the TREAT operator
therefore also has the effect of filtering on the specified type (and its subtypes) as well as performing the
downcast." (section 4.4.9).
In the case of nulls, they are not the specific type, and so do not participate in the result. What you seem to be looking for might be
"Select a FROM Entity a LEFT JOIN a.parent b where TYPE(b)=B"
Special handling for "SELECT A FROM Entity a LEFT JOIN TREAT(a.parent AS B) b" seems a useful feature/enhancement though.
|
|
|
Powered by
FUDForum. Page generated in 1.03800 seconds