Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Eclipselink 2.6.4 LEFT JOIN TREAT QUERY Not working properly
Eclipselink 2.6.4 LEFT JOIN TREAT QUERY Not working properly [message #1749385] Tue, 06 December 2016 07:38 Go to next message
Nuno Godinho de Matos is currently offline Nuno Godinho de MatosFriend
Messages: 34
Registered: September 2012
Member
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 07:41]

Report message to a moderator

Re: Eclipselink 2.6.4 LEFT JOIN TREAT QUERY Not working properly [message #1749406 is a reply to message #1749385] Tue, 06 December 2016 10:11 Go to previous messageGo to next message
Nuno Godinho de Matos is currently offline Nuno Godinho de MatosFriend
Messages: 34
Registered: September 2012
Member
Hi,

A sample application now exists for this bug.
Please take a lool.
https://github.com/99sono/EclipseLink_2_6_4_LEFT_JOIN_TREAT_BUG

In this sample application you will have two unit tests.
A placebo tests showing a normal working left joing.
And a ltest that uses a query with LEFT JOIN treat query where the behavior of the query is not at all like a LEFT JOIN.

Finally, please bare in mind that the appropraite query predicate for a LEFT JOIN TREAT should never involve an equality predicate.

THe appropriate implementation of a such a predicate has to use an IN statement.

Of the form:
joinTable.classfier IS NULL
OR joinTableClassifiser IN ( listOf classifiers that are under the TEART entity hiearchy).

Thanks, for taking a look.
Re: Eclipselink 2.6.4 LEFT JOIN TREAT QUERY Not working properly [message #1755222 is a reply to message #1749406] Wed, 01 March 2017 09:55 Go to previous messageGo to next message
Christian Beikov is currently offline Christian BeikovFriend
Messages: 7
Registered: May 2016
Junior Member
Seems EclipseLink is dead. I asked a question(https://www.eclipse.org/forums/index.php/t/1080319/) about this strange treat behavior a long time ago and still didn't get any feedback.
Re: Eclipselink 2.6.4 LEFT JOIN TREAT QUERY Not working properly [message #1755692 is a reply to message #1755222] Mon, 06 March 2017 20:13 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
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.
Previous Topic:Connection does not get closed after entityManager.getTransaction().commit(); call
Next Topic:Eclipselink error 3002
Goto Forum:
  


Current Time: Fri Mar 29 01:16:00 GMT 2024

Powered by FUDForum. Page generated in 0.02986 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top