Skip to content

specialized expression types for easier JPA Criteria#936

Merged
gavinking merged 25 commits intojakartaee:mainfrom
gavinking:#519
Feb 20, 2026
Merged

specialized expression types for easier JPA Criteria#936
gavinking merged 25 commits intojakartaee:mainfrom
gavinking:#519

Conversation

@gavinking
Copy link
Copy Markdown
Member

@gavinking gavinking commented Jan 30, 2026

@beikov had already done most of the hard work in #522.

This is a light reworking of that PR.

@gavinking
Copy link
Copy Markdown
Member Author

Still need to figure out what to do about BooleanExpression vs Predicate. We didn't bother with a BooleanExpression in Data 1.1. I'm OK with leaving it in here, but if are going to have a BooleanExpression type, we don't need Predicate anymore and we can deprecate it.

Copy link
Copy Markdown

@jwgmeligmeyling jwgmeligmeyling left a comment

Choose a reason for hiding this comment

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

All my review comments from the #522 PR are incorporated in this PR.

Copy link
Copy Markdown
Contributor

@beikov beikov left a comment

Choose a reason for hiding this comment

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

Other than the missing mod function, this looks good to me. Maybe we should add overloads for the various methods where currently Predicate is accepted to also accept BooleanExpression and change return types to return BooleanExpression? Then we can deprecate Predicate.

@gavinking
Copy link
Copy Markdown
Member Author

I have tried replacing Predicate with BooleanExpression or Expression<Boolean> in locations where that would not break backward compatibility. It's not perfect, we still have Predicate in some return types, but it's not terrible either.

Comment thread api/src/main/java/jakarta/persistence/criteria/AbstractQuery.java
@gavinking
Copy link
Copy Markdown
Member Author

I do believe this is ready to go. In the end I did not see any way to really untangle Predicate without major breakage to existing programs. But it's fine, we can live with that.

Also I have aligned naming of numeric operations with what we have in Jakarta Data.

beikov and others added 16 commits February 20, 2026 12:03
- fixed NumberExpression to extend ComparableExpression
- fix up typing of methods of ComparableExpression
- fix broken overloading of CriteriaBuilder.literal()
- try to maintain some sort of distinction b/w Predicate + BooleanExpression
- move sorting methods down to ComparableExpression (debatable)
- removed unnecessary overloads of Path.get()
because "Number" is not an adjective
unfortunately overloading here just doesn't work
and remove redundant overrides
@gavinking
Copy link
Copy Markdown
Member Author

gavinking commented Feb 20, 2026

I do believe this is ready to go.

Spoke too soon. I have made the following additional changes:

  1. Removed the unnecessary XxxxPath types which represented terminal paths. The API is nicer if we just use XxxxExpression for this.
  2. Aligned naming with Jakarta Data, so TextExpression instead of StringExpression.
  3. Aligned operations of TextExpression with Jakarta Data.
  4. Simplified naming of XxxxAttribute types, and made NumericAttribute a ComparableAttribute.
  5. Fixed a couple of generic method signatures.
  6. Changed CollectionExpression to PluralExpression so it can represent Maps.

@gavinking
Copy link
Copy Markdown
Member Author

gavinking commented Feb 20, 2026

Now I think this is ready to go. If there are further adjustments to be made, they can be done in separate pull requests. Need to (finally) get this merged so that people can experiment on the implementation side.

@gavinking
Copy link
Copy Markdown
Member Author

Going to pull the trigger on this in 3 ... 2 ... 1 ....

@gavinking gavinking merged commit f076d77 into jakartaee:main Feb 20, 2026
3 checks passed
@gavinking
Copy link
Copy Markdown
Member Author

Merged. If anyone has further suggestions, send a PR or open an issue.

@gavinking gavinking removed candidate-for-4 Good candidate for JPA 4 PRIORITY labels Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce specialized expression types for easier JPA Criteria querying

3 participants