Null Handling of Repository Methods not implemented correctly for "Containing" kind of methods
See original GitHub issueIn the documentation we see that it is possible to manage nullability for the repository methods. Look at section 9.4.7 Null Handling of Repository Methods.
While it works for simple methods like:
User findByEmailAddress(@Nullable EmailAddress emailAdress);
The same approach will cause an error for “Containing” kind of methods:
User findByFirstnameContaining(@Nullable String name)
If I call this method with null name
I get this error: "message": "Argument for creating $regex pattern for property 'section' must not be null!"
I think the more appropriate solution would be omitting any null input parameter during query building phase.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Spring data JPA and parameters that can be null
I have extend the answer: When using the Spring data JPA @Query annotation, you have to use two separate query methods. One for...
Read more >Improve handling of null query method parameter values ...
RC1 and prior, query methods expect non-null values. If a null value is passed in to a query method, the JPQL generated includes...
Read more >1. Working with Spring Data Repositories
As a first step you define a domain class-specific repository interface. The interface must extend Repository and be typed to the domain class...
Read more >Implementing the Repository and Unit of Work Patterns in an ...
For the Student entity type you'll create a repository interface and a ... This code declares a typical set of CRUD methods, including...
Read more >How to Avoid Returning Null from a Method - Coding Helmet
Instead, method was executed successfully but the result is not any ... value for the item type T – in reference types that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sounds that you have already a suggestion on your mind how the docs should look like. I’d be happy to review a pull request that changes https://github.com/spring-projects/spring-data-commons/blob/main/src/main/asciidoc/repository-query-keywords-reference.adoc by introducing another column whether the specific keyword would accept a nullable argument.
I would like to insist on more specific wording. “makes sense” is not specific enough. It should specifically mention incompatibility between
@Nullable
String input and all queries built using keywords:Like
,StartingWith
,EndingWith
,NotLike
,IsNotLike
,Containing
on String,NotContaining
on String.