Repository navigation
[OPENJPA-2975] Narrow criteria TREAT joins instead of casting silently - #194
Merged
Merged
Conversation
The treat(Join/CollectionJoin/SetJoin/ListJoin/MapJoin, Class) overloads only cast their argument, so no type narrowing was applied at all. A treated join now resolves its attributes against the narrowed type and binds its kernel variable to the narrowed metadata, which renders the same discriminator condition as a JPQL TREAT join, including the subclasses of the treated class. A join that is correlated to an outer query, or that is reached from such a join, carries no kernel variable of its own, so there is no variable that could carry the narrowed metadata. Such a join is now rejected with an UnsupportedOperationException rather than being narrowed without any effect. treat(Path, Class) delegates to the Root and Join implementations and rejects any other path expression with an UnsupportedOperationException instead of returning it unnarrowed. The type restriction of a treated root is evaluated after the projection and ordering terms, so that it is applied for a root that is treated in the select clause only, and it now matches the subclasses of the treated class as well.
cristof
approved these changes
Sep 26, 2026
cristof
left a comment
Contributor
There was a problem hiding this comment.
I'd rather use some enhanced loops in the test, but it seems good enough.
solomax
reviewed
Sep 28, 2026
| TLineItem.class, TOrder.class, DROP_TABLES); | ||
|
|
||
| try (EntityManager em = emf.createEntityManager()) { | ||
| em.getTransaction().begin(); |
Contributor
There was a problem hiding this comment.
shall the rollback be called in case of error? (with nested try?)
Of it should be handled automatically?
Contributor
There was a problem hiding this comment.
If it fails, all tests fails. Repeating the test will call DROP_TABLES. I've fixed the varargs warnings and thus gonna merge it.
solomax
reviewed
Sep 28, 2026
Contributor
There was a problem hiding this comment.
how hard would be to eliminate these warnings?
solomax
approved these changes
Sep 28, 2026
cristof
approved these changes
Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
treat()on a join only cast the object, so no type narrowing was applied and queries silently returned supertype instances. The join now records the narrowed type, which makes attribute resolution work against the subclass and the kernel emit the same TREAT discriminator condition as JPQL (OPENJPA-2961); a treated root used only in the SELECT clause is now restricted too. Narrowing a correlated join andtreat()on an arbitrary path are rejected with a clearUnsupportedOperationExceptioninstead of silently doing nothing, andTestTreatJoinCriteriacovers both the narrowing and the diagnostics.