-
Notifications
You must be signed in to change notification settings - Fork 685
Move to better naming scheme of methods in repository interfaces [DATACMNS-944] #1399
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
Comments
Andy Wilkinson commented I like the new names a lot. FWIW, I'd go with |
Heiko Scherrer commented Looks more streamlined. I would be more precise on #3: What is an ID? An unique identifier. Is it the persistent key or is it the business key? It is the persistent key. So call it PK. findByPk(..). Not to confuse with "primary key"! Often I've used something like: findByPk(42) and findByBk("me@home.com"). The latter is of course not part of the API. In contrast to Andy I'd call the exists method existsForPk(..) |
Edward Beckett commented
|
Oliver Drotbohm commented Heiko Scherrer — I don't think we're gonna go with PK as it has an inherently relational touch. The repository is supposed to abstract from that. Wouldn't you rather also have a dedicated name for the business key? like |
Kai Tödter commented +1 for the new names |
Milan Milanov commented Great proposal. I'd go with existsById though, just for consistency |
Bartłomiej Tartanus commented Great! I love the new names! |
André Schäfer commented How about backwards compatibility? |
Juergen Zimmermann commented (y) for the names, especially the *ById *suffix |
Oliver Drotbohm commented I've updated André Schäfer — This is a proposal for 2.0 in which we're gonna introduce some breaking change anyway as we will hardly ever have the chance to do so any time after that. So we were rather thinking that if we make those anyway, let's get more things right this time |
František Hartman commented What about cases where internal id is different than id property/field (hence findOne and findById have different sematics)? E.g.: I could map mongo _id to different field than id using Similarly in Spring Data Neo4j findOne searches by internal graph id and people may have another field id (that translates to property id) - it is actually quite common there because people are discouraged to use the internal id directly as it is offset in database file and may change between restarts. I don't know about other Spring Data projects, there might be more examples.. |
Oliver Drotbohm commented In this case "id" doesn't refer to a property named "id" as we — just as before — would obtain the identifier from whatever the store implementation considers to be one. Actually, that's one of the reasons we have abstained from using So summarizing: if you declare a method |
František Hartman commented That all makes sense, but will eventually result in not being able to do following:
|
Oliver Drotbohm commented I think it should work if you annotate the method with |
Marcos Abel commented (y) all the proposed changes make sense to me |
Heiko Scherrer commented +1 František Hartman fully agree! |
Ali Shahbour commented What about supporting Slice<T> instead of Page<T> , to get bypass the count query ? DATAJPA-961 |
Oliver Drotbohm commented We can certainly look into options of introducing new methods to support |
Benjamin Schmeling commented ById suffix makes sense for me, it is more consistent. What about findAll(Iterable ids)? Shouldn't we rename it to findAllByIds(Iterable ids)? |
Jens Schauder commented What about
Wouldn't they also cause conflicts, when T is an Iterable? Maybe the first should be renamed to |
Oliver Drotbohm commented We're gonna stick to the |
Gary Hodgson commented I realise this issue is closed, and released in GA, but I just wanted to say that the whilst it may have solved some problems it introduces others (e.g. my SO question here). It seems a sub-optimal design decision to use method names in the parent interface that are valid queries for child repositories, thus resulting in either conflicts or (worse) inadvertently overriding behaviour. Having The suggestion from Oliver above is sufficient to resolve the problem, but now our team has to be ever vigilant that the It would have been better if this Jira had resulted in method names that are not valid query methods |
Gary Hodgson commented Something else worth noting regarding the shadow method workaround: calls do not hit the L2 Cache |
Oliver Drotbohm opened DATACMNS-944 and commented
The current naming scheme for methods in
CrudRepository
cause quite a few problems. Especially the methods taking parameters that are generic type variables. Under bad circumstances they could effectively resolve to the same methods and cause ambiguities.With the 2.0 release we have the chance to correct those mistakes and the following scheme is suggested (pseudo code):
The methods that are effected by a change are marked with a comment here. The new scheme is driven by the following requirements:
delete(…)
methods could effectively resolve to the same type.…All(…)
affect a collection of items and/or return one.…ById(…)
.ID extends Serializable
requirement, which is not possible without that change as then thedelete(…)
methods would be ambiguousIssue Links:
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
("is depended on by")
1 votes, 18 watchers
The text was updated successfully, but these errors were encountered: