Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-06-2021 01:53 PM
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
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:
But every time i get empty properties list
[
{
"name": "Awesome Cocktail",
"steps": [
{
"number": 1,
"desc": []
}
]
}
]
What am I missing?
Thanks in advance!
Solved! Go to Solution.
09-07-2021 08:43 AM
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
09-06-2021 04:22 PM
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
09-07-2021 08:43 AM
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
09-10-2021 03:17 AM
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.
09-08-2021 12:32 AM
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
All the sessions of the conference are now available online