Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

Null param in a Repository query



We recently switched to the latest Springboot version (well 2.4.0 since it already not the latest anymore) and tried to be ogm-free. Our app works fine but we've noticed a warning we didn't see before (I don't think it happened, but maybe we just didn't noticed?).
Anyway, here's the thing: one of our queries is in a repo and just returns a string after editing relationships. Pretty simple query. The thing is, the api route that executes this query takes a "user" param used to set the "modified_by" attribute in our graph.
Because of work with the UI team and the fact that this feature once didn't exist, this param isn't mandotory and thus, set to null when not provided. This was perfect since cypher treats
SET n.modified_by = $user
by not doing anything when the param is null. This actually works like a charm!
The only thing is we get a WARN each time it happens:
2021-01-04 10:48:30.382 WARN 11695 --- [nio-8080-exec-1] o.s.d.n.r.query.Neo4jQuerySupport : Do not use null as a property value for comparison. It will always be false and return an empty result.
This happens whether the null param actually is used or not in the Cypher query: the WARN is issued when the @Query takes the null param in.
Of course, we could now just forbid the param being omitted since our UI has now caught up, but I was wondering if someone new how to avoid that? We also would rather avoid having 2 different (but almost identical) queries for each case( user filled // user not provided).
thanks in advance and a happy new year to everyone!


Graph Steward

The problem is not with this statement when $user is null

SET n.modified_by = $user

I tried this with the Movie DB and got no error:

MATCH (p:Person { name: 'Tom Hanks' })

I believe the problem is some where you have a test that is something like:

WHERE n.modified_by = $user

then you'll get the error when $user is null. This is because null = null doesn't "make sense" in that in the Neo4J world. null = null is trying to test whether some missing value is the same as some other missing value.

You can take advantage of "short circuit" logic (common in all programming languages) to avoid this problem. This condition tests for null first and returns true if n.modified_by is null and skips the second test (which causes the error.). It can do so because once the first part of the OR statement is true, you don't need to execute the second part because the entire test will be true regardless.

WHERE n.modified_by is null OR n.modified_by = $user



Thanks for your answer! I'm 100% sure it isn't the case though, because my initial query doesn't have any comparison of this type. The only part where I use the $user param is to set
SET n.updated_by = $user

But just to be sure I replaced the entire content of the query with RETURN "test" so that no param was used at all, and no comparison was made and the warning still arose.

Node Link

I am also being troubled by this error, after upgrading to the latest version of the OSN. My problems comes with trying to execute a query that returns a project as a DTO I simply can't get this to work.

I get this error, and the values returned are always NULL. Did you ever get a solution?



Unfortunately, I won't be of any help since it was always planned to make the user mandatory and in our case, that's just what we did so I kind of lost sight of this issue.
I'm not sure you're talking about this but: I've also had problem switching "off" OGM, specifically to map query results to my objects (I used @QueryResult to automatically map cypher responses to ad hoc objects) and never could get DTOs or dynamics projections to work. I ended up writing my own mappers to take the returned Record and make it into my different objects.

I'm still interested if someone can explain, though.

Thanks - Yes, my problem is exactly this issue of DTO not returning values. I only have six, so I guess I will have to work around them.

Node Link

I get the same warning regarding null values used for comparison with the following query in Spring Boot 2.4.5:

MATCH (questionResponse:QuestionResponse)
WHERE questionResponse.optionId = $optionId
AND (($ratingId IS NULL AND questionResponse.ratingId IS NULL) 
OR ($ratingId IS NOT NULL AND questionResponse.ratingId IS NOT NULL AND questionResponse.ratingId = $ratingId))
RETURN questionResponse

where $optionId is never null, but $ratingId can be null.
I couldn't figure out the fix for this warning.