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).
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.
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
The text was updated successfully, but these errors were encountered: