-
Notifications
You must be signed in to change notification settings - Fork 694
Description
justin mccune opened DATACMNS-1213 and commented
Many think that it's great to use the name of the method to infer the SQL for a query on a repository. However, often the use of descriptive field names and one or two concerns (an AND operation with a SORT ordering) leads to incredibly long (or "ugly" names). For example one properly named long field and a simple boolean & sort order lead to the repository method name being 96 characters long. This destroys many style guides line-lengths when used.
While it is an alternative to use @Query
make a shorter method name and write the actual query by hand, or to use java's "default" on interface to alias a shorter form that uses the full / ugly query. They both are not as elegant as the simplicity of the named query where preferably I alias it.
Often the alias / shorter name is just as meaningful and clear in meaning even if omitting implicit/assumed context-- see examples below.
This has come up several times with coworkers (in multiple companies) & a quick search has shown that others have the same concern.
When I read the above, I thought perhaps I'd found the solution-- but it was a suggestion that I couldn't find in the Spring Data feature request list, so I thought I'd add it.
So what I'd like would be something like the below-- where the annotation name is used instead of the actual method name to build the query.
@QueryByMethodName("findOneByDeletedIsFalseAndEmail")
User findOneByEmail(String email);
@QueryByMethodName("findOneByReallyLongFieldNameAndActiveStatusIsTrue")
Entity findOneByRLFN(ReallyLongFieldNameType value)
This improves both simplicity and readability. And I'm not particular about the annotation name.
16 votes, 8 watchers