Loading...
18

I have a JPA Repository method that should return a List, but it returns null instead of an empty list when no results are found.

__CODEBLOCK0__

I expected an empty list but got null. Is this normal?

asked 2 days ago

Log in to add a comment.

1 Answer

15

Spring Data JPA should return an empty list, not null. If you're getting null, check for these common issues:

  1. <strong>Make sure you're not using @Query with native = true without proper mapping</strong>
  1. <strong>Check if you have any AOP aspects or interceptors</strong> modifying the return value
  1. <strong>Ensure your repository is properly injected</strong> (not manually instantiated)
Here's the correct usage: __CODEBLOCK0__

If you're still getting null, share your complete entity and repository code.

answered 2 days ago
Log in to answer this question.
Question Stats
Asked: 2 days ago
Views: 658
Active: 1 hour ago
Related Tags