Skip to content

[OPENJPA-2987] Restore externalized-parameter assertions - #152

Open
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2987
Open

[OPENJPA-2987] Restore externalized-parameter assertions#152
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2987

Conversation

@rzo1

@rzo1 rzo1 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Follow-up on #144 (comment) (OPENJPA-2987).

Answer to the review question

Externalized-parameter detection was not removed. PreparedQueryImpl.extractSelectExecutor() still calls isUsingExternalizedParameter(...) and excludes such queries from the prepared query cache. With trace logging enabled:

Query "select b from Book b where b.token=:token" is removed from cache excluded permanently.
... is not cached because some parameterized field values are externalized.

What broke was only the test's access to the expressions: JPA 3.2 requires a mutable getResultList(), so org.apache.openjpa.persistence.QueryImpl.getResultList() now returns new ArrayList<>(delegate) and the (ResultList) result cast in the old getExpressions() helper no longer works. The cache itself is unaffected, since postExecute() still receives the raw ResultList.

Change

TestExternalizedParameter gets its original assertions back:

  • getExpressions(...) helper restored
  • assertFalse(...) / assertTrue(isUsingExternalizedParameter(exps[0])) restored in place of the no-op assertNotNull(getResultList())
  • the ResultList is obtained by executing the kernel query directly (((QueryImpl<?>) em.createQuery(jpql)).getDelegate().execute(params)) instead of through the JPA facade

Test

mvn -pl openjpa-persistence-jdbc -Dtest=TestExternalizedParameter test -> Tests run: 3, Failures: 0, Errors: 0.

Note

While looking for a cache-level assertion instead: PreparedQueryCacheImpl.isExcluded(id) only matches user-supplied exclusion patterns. Per-query exclusions are stored in _uncachables and are only observable via isCachable(id) == FALSE, with no accessor for the exclusion reason. Since every Book query is uncachable anyway (eager @ManyToMany -> multiple SQL statements), that route cannot distinguish an externalized-parameter exclusion from any other, so the kernel-level assertion is the one that actually discriminates.

The three "CanDetectExternalized..." tests had been reduced to
assertNotNull(getResultList()), which can never fail, after JPA 3.2 made
getResultList() return a mutable ArrayList copy instead of the internal
ResultList the assertions relied on.

Externalized-parameter detection is still in place (PreparedQueryImpl
excludes such queries from the prepared query cache), so the original
assertions are restored by executing the kernel query directly, which
still yields the ResultList carrying the QueryExpressions user object.
@rzo1 rzo1 self-assigned this Aug 20, 2026
@rzo1
rzo1 requested a review from solomax August 20, 2026 10:08

@solomax solomax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was fast :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants