Skip to content

Add type-safe property paths overloads (#2126)#2128

Open
emilienbev wants to merge 4 commits intoAddFTSfrom
AddTypeSafetyPropertyReferences
Open

Add type-safe property paths overloads (#2126)#2128
emilienbev wants to merge 4 commits intoAddFTSfrom
AddTypeSafetyPropertyReferences

Conversation

@emilienbev
Copy link
Copy Markdown
Collaborator

@emilienbev emilienbev commented Apr 7, 2026

Fixes #2126

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

This comment was marked as low quality.

Fixes #2085

Signed-off-by: Emilien Bevierre <emilien.bevierre@couchbase.com>
Fixes #2126

Signed-off-by: Emilien Bevierre <emilien.bevierre@couchbase.com>
@emilienbev emilienbev force-pushed the AddTypeSafetyPropertyReferences branch from 574f973 to 4096ed0 Compare April 9, 2026 08:28
Signed-off-by: Emilien Bevierre <emilien.bevierre@couchbase.com>
Copy link
Copy Markdown
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

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

This is a great start. I suggest to consider using <T> someMethod(TypedPropertyPath<P, ?>... paths) instead of TypedPropertyPath<?, ?> to constrain the originating entity type to a single type T. The context is e.g. distinct(Person::getName, Person::getAge) where you would likely want to avoid property references to other entities such as distinct(Person::getName, Order::getId). distinct(Person::getName, TypedPropertyPath.of(Person::getOrder).then(Order::getId) would still work because T is in both cases Person as the origin entity.

* @param distinctFields the property paths to use as distinct fields.
* @since 6.1
*/
default Object distinct(TypedPropertyPath<?, ?>... distinctFields) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Introducing <T> to distinct(TypedPropertyPath<T, ?>... distinctFields) allows to limit property paths originating in the same type. This e.g. prevents distinct(Person::getName, Order::getName) as both properties come from different entities.

*
* @param fields the property paths to project.
* @since 6.1
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Constraining to R could make sense.

Signed-off-by: Emilien Bevierre <emilien.bevierre@couchbase.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants