question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null Handling of Repository Methods not implemented correctly for "Containing" kind of methods

See original GitHub issue

In 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.

image

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:open
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mp911decommented, May 12, 2021

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.

0reactions
vgarmashcommented, May 12, 2021

We could improve the wording to mention that nullability annotations make only sense for parameters in which it actually makes sense.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found