Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive queries as in method name, but with annotation [DATACMNS-1481] #1914

Closed
spring-projects-issues opened this issue Feb 16, 2019 · 1 comment
Assignees
Labels
status: declined

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Feb 16, 2019

Juan Marcos Bellini opened DATACMNS-1481 and commented

The repository proxy has two ways to derive a store-specific query from the method name:

  • By deriving the query from the method name directly.

  • By using a manually defined query.

This is great but, what if the query is very long and complicated. You might end up having a long method name. The code using this method will be a bit difficult to read.

What if there is some kind of annotation (like the @Query annotation) where you can specify what you want, as when defining the method name, instead of writing your manual query. After all, as I see it, the query is an implementation detail, and the repositories are interfaces.

 

For example, suppose that you have an Entity that has an Instant createdAt field, and another field. If you want to retrieve the lastly created, filtering by that field, you will need to create some method like this: findTopByFieldOrderByCreatedAtDesc, which is a bit uncomfortable to use by the consumer of the repository. It would be great to be able to write: @Derive(findTopByFieldOrderByCreatedAtDesc) findLastByField. Query derivation is performed using what the annotation contains, instead of the method name (as with the @Query annotation), but I could write a very high level specification of what I want (not a real HQL, SQL, o whateverQL).
 


No further details from DATACMNS-1481

@spring-projects-issues spring-projects-issues added in: repository type: enhancement labels Dec 30, 2020
@mp911de mp911de added status: waiting-for-triage and removed in: repository type: enhancement labels Feb 15, 2021
@mp911de mp911de assigned mp911de and unassigned odrotbohm Feb 15, 2021
@mp911de mp911de added status: declined and removed status: waiting-for-triage labels Feb 15, 2021
@mp911de
Copy link
Member

@mp911de mp911de commented Feb 15, 2021

We don't plan to add that feature. Introducing arbitrary strings opens up another set of problems. Also, query derivation is intended for simple cases. If your method name grows beyond an acceptable length, then the long method name is rather a symptom than the cause and we recommend using string-based queries via @Query.

@mp911de mp911de closed this as completed Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined
Projects
None yet
Development

No branches or pull requests

3 participants