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

The findAll method from the JpaRepository is an Anti-Pattern and the HibernateRepository should deprecate it #483

Closed
vladmihalcea opened this issue Sep 10, 2022 · 3 comments
Assignees
Milestone

Comments

@vladmihalcea
Copy link
Owner

The findAll method from the JpaRepository is a terrible anti-pattern as it allows you to fetch an entire database table with a single method call. Such methods have no purpose in a non-trivial application, so this method should be deprecated.

If you really want to fetch an entire database table, then you should do that explicitly with a JPQL call in the context where this is needed.

@vladmihalcea vladmihalcea added this to the 2.19.1 milestone Sep 10, 2022
@vladmihalcea vladmihalcea self-assigned this Sep 10, 2022
@vladmihalcea vladmihalcea changed the title HibernateRepository deprecates the findAll method from the JpaRepository The findAll method from the JpaRepository is an Anti-Pattern and the HibernateRepository should deprecate it Sep 10, 2022
vladmihalcea added a commit that referenced this issue Sep 10, 2022
@vladmihalcea
Copy link
Owner Author

Fixed.

@ethanmills
Copy link

I don't think I agree that there are no valid usages of this in a non-trivial application. There are ~1.6M usages of this method on Github: https://github.com/search?l=Java&q=repository.findAll%28%29&type=Code

@vladmihalcea
Copy link
Owner Author

vladmihalcea commented Sep 12, 2022

The article about this topic will be published tomorrow.

It's a very dangerous method that can fetch an entire database table, and it encourages inexperienced devs to use Java,Stream filter/map instead of using WHERE/SELECT in SQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants