Spring Data Neo4j does not return Relation Properties

Hi!

I've read documentation several times. I've looked throught tickets but i didn't find an answer.

I'm trying to extract Relationship Properties using @RelationshipProperties, but I get empty List every time :frowning:

Here my code
Dependencies

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.5.4</version>
		<relativePath/>
</parent>

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>

Entity Cocktail

@Data
@Node(value = "Cocktail")
public class CocktailEntity {
    @Id
    private String name;

    @Relationship(value = "DESCRIPTION",direction = Relationship.Direction.OUTGOING)
    private Set<StepEntity> steps;

}

Step Entity

@Node(value = "Step")
@Data
public final class StepEntity {
    @Id
    private int number;

    @Relationship(type = "DESCRIPTION", direction = Relationship.Direction.INCOMING)
    private final List<StepDescEntity> desc;
}

Relationship "DESCRIPTION" Entity

@RelationshipProperties
@Data
public final class StepDescEntity {
    @Id
    @GeneratedValue
    private final Long id;

    @TargetNode
    private final StepEntity stepEntity;

    private final List<String> properties;
}

Cocktail Repository

public interface CocktailRepository extends Neo4jRepository<CocktailEntity, String> {
}

I tried:

  • findAll() method
  • using @Query("match (c:Cocktail)-[r:DESCRIPTION]-(s:Step) return c,collect(r),collect(s)")

But every time i get empty properties list

[
    {
        "name": "Awesome Cocktail",
        "steps": [
            {
                "number": 1,
                "desc": []
            }
        ]
    }
]

What am I missing?

Thanks in advance!

Hello Evyuel
Just by chance, yesterday I started reading the book, it has detailed examples that show complete integration with Neo4j and Spark, hope this will help you solve the bug.
The examples are very similar to the case you presented, hope this helps.
Regards
Rafi

The main issue is that you have the property String value in the graph but model List<String> properties.
If you would add the property String value in the StepDescEntity, the property will get mapped.
But you did not model the relationship StepDescEntity between Cocktail and StepEntity (from the Cocktail side) but the StepEntity directly.

@Relationship(value = "DESCRIPTION",direction = Relationship.Direction.OUTGOING)
private Set<StepDescEntity> steps;

should fix this.
Also, you do not need to model the relationship bidirectional and can remove the StepDescEntity from the StepEntity. It is recommended (and more performant during the mapping phase) to have a directed graph modeled in the Java world instead of cycles.
I added an example for your use-case here: https://github.com/meistermeier/neo4j-issues-examples/tree/master/discourse-44037

1 Like

Hello Evyuel
Pages 45-47,
Pages 65-67 describe algorithm how return all Shortest path with Neo4j & Spark.
There is alot exempales with code .
The difference is only in the syntax and examples ,but the ideas are very similar to your case.
Regards

1 Like

Thanks everybody!

@gerrit.meier You solved my problem!!
My main mistake was that I added to the "target node" class, the repository for which I am using, at the same time a reference "to the entity of the related node" and a reference "to the entity of the relationship".
Instead, I needed to add a reference "to the entity of the relationship" to the "related node entity" rather than the target node.