OGM: MappingException: Relationship entity cannot have a missing start or end node

I have 2 entities, Player(p) and Team(t) and I am trying to create the following rich relationship while adding a new Player with an existing team:


However when I try to do this, I get an exception stating:
MappingException: Relationship entity com.ipfl.data.domains.PLRole@669056a1 cannot have a missing start or end node.

Below are the classes:

public class Player extends Person {

	private String nationality;
	private PLRole plrole;

@RelationshipEntity(type = "PLAYS_FOR")
public class PLRole {

@Id @GeneratedValue
Long id;

private Set<String> plroles;

private Player player;

private PLTeam plteam;

public class PLTeam {
	@Id @GeneratedValue
	Long id;
	private String name;

Below is the JSON i am sending to my application via REST:
curl -d '{"name":"Player1","nationality":"Country1","plrole":{"plroles":["Batsman","Captain"],"plteam":{"id":41,"name":"Team1"}}' -H"Content-Type: application/json" -X POST http://localhost:8080/player/create

How can this error be fixed? WHat would I be doing wrong?

If you're trying to put a label on your relationship, then this is what you need to do:

(p)-[:PLAYS_FOR {position: "Batsman"}]->(t)

Unfortunately in Neo4j, you cannot dynamically assign the relationship with a variable, so ensure you're placing labels like that. In addition do you have a representation of the query you're trying to run in Cypher? Like:

MATCH (p:Player {id: "PlayerID"})-[r:PLAYS_FOR]->(t:Team {id: "TeamID"})
SET r.postion = "Batsman"

Something of that nature? It'll help to understand what you're doing because your error is explicitly stating that you're failing to provide a start or end node to your process.

Thank you Michael for the response!

I haven't written an explicit Cypher for this.

I was hoping OGM to handle it, like it does when creating simple relationship. My expectation was while creating Player(which is the start node), pass the PLRole (Which is the Rich Relationship) details and OGM will be able to map it. However this seems to be an incorrect approach.

No worries, yeah it looks like you'll need to create a function to call an internal Cypher query to make that update. Hopefully, you're on the right path now and welcome to the community!

Thank you Michael! Yes, I am able to persist rich relationship now, though I am not sure its the most ideal way to do it. (GIT Link: https://github.com/rnairg/ipfl/tree/master/src/main)