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

JpaRepository.getOne/getById method name should indicate that it returns a reference #2232

Closed
kdebski85 opened this issue Jun 9, 2021 · 2 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@kdebski85
Copy link

JpaRepository methods getOne/getById methods are often used by accident by inexperienced developers instead of findById.
These methods call EntityManager::getReference and return a reference.
The method name should indicate that.
We should consider adding method JpaRepository::getReferenceById and deprecating getById (getOne is already deprecated).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 9, 2021
@schauder
Copy link
Contributor

schauder commented Jun 9, 2021

Related: #1645, #510, #1540, #1473

@schauder schauder added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 14, 2021
@schauder
Copy link
Contributor

We agree with the proposed solution.

@schauder schauder assigned gregturn and unassigned schauder Jul 1, 2021
gregturn added a commit that referenced this issue Jan 4, 2022
gregturn added a commit that referenced this issue Jan 4, 2022
Introduce a repository method that makes it clear the return is a reference. Deprecate the previous methods.

See #2232.
gregturn added a commit that referenced this issue Jan 4, 2022
Introduce a repository method that makes it clear the return is a reference. Deprecate the previous methods.

See #2232.
gregturn added a commit that referenced this issue Jan 4, 2022
Introduce a repository method that makes it clear the return is a reference. Deprecate the previous methods.

Closes #2232.
schauder added a commit that referenced this issue Jan 5, 2022
Corrected issue number comments.

See #2232
Original pull request #2398
schauder added a commit that referenced this issue Jan 13, 2022
schauder added a commit that referenced this issue Jan 21, 2022
awood added a commit to RedHatInsights/rhsm-subscriptions that referenced this issue Jun 1, 2022
Spring Data deprecated getById because it didn't do what people thought
it did.  Rather than fetching the entity, getById returned a JPA proxy
object.  The method has been replaced with the more accurately named
getReferenceById.  In the case of the code this commit patches, it
appears that the original author wanted the semantics associated with
findById and got tripped up by the confusing naming.

See spring-projects/spring-data-jpa#2232
awood added a commit to RedHatInsights/rhsm-subscriptions that referenced this issue Jun 1, 2022
Spring Data deprecated getById because it didn't do what people thought
it did.  Rather than fetching the entity, getById returned a JPA proxy
object.  The method has been replaced with the more accurately named
getReferenceById.  In the case of the code this commit patches, it
appears that the original author wanted the semantics associated with
findById and got tripped up by the confusing naming.

See spring-projects/spring-data-jpa#2232
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants