0
votes

I have a pretty typical situation using the new Spring Data Neo4j-RX, where I'm fetching an object and wanting to get one level of relationships in the resulting object. My stuff was originally written against Neo4j 3.5, with the OGM, and there it worked fine. Because I'm using Kotlin, I want to handle null as the "does not exist" case, rather than Java Optional.

The code is pretty straightforward:

@Query("MATCH (a:Foo {id: \$id})-[r]->(o) RETURN a, r, o")
fun findByIdOrNull(id: String): FooNode?

But this doesn't work. Running the cypher query directly against the driver seems to return the correct structure - we get the parent object, the relationship, and the target object. All the IDs match, etc. But the property in the parent object is left as null.

If I use the regular old findById() and handle the Optional result, it works fine. It seems like I must be doing something wrong, but I don't know what it is.

1

1 Answers

0
votes

Update: the below doesn't work in the general case. It worked with one particular case, but not an expanded one.


So, I dug through the DefaultNeo4jConverter code and realized that it was looking for lists of relationships in the raw result. Having seen the collect() Cypher function on an example somewhere I added it, so the code looks like this:

@Query("MATCH (a:Foo {id: \$id})-[r]->(o) RETURN a, collect(r), collect(o)")
fun findByIdOrNull(id: String): FooNode?

And it works. This doesn't quite make sense to me. It seems a notable backwards incompatibility to not be mentioned in the docs (for example, in the migration guide at https://neo4j.github.io/sdn-rx/current/#Migrating). So, I'm assuming I'm still missing something.

I'm going to file a bug on the Neo4j project and see what they say.