Thursday, 22 August 2013

unable to create more than 2 same relations between two nodes

unable to create more than 2 same relations between two nodes

Spent multiple days trying to figure out why this isn't working. My model
is Player-[:PLAYED_WITH_TEAM]->team-[:CONTESTED_IN]->league. Few instances
of this relation is as follows
bob-[:PLAYED_WITH_TEAM]->falcons-[:CONTESTED_IN]->ABC League
alice-[:PLAYED_WITH_TEAM]->falcons-[:CONTESTED_IN]->ABC League
bob-[:PLAYED_WITH_TEAM]->falcons-[:CONTESTED_IN]->XYZLeague
Bob played for the same team "Falcons" in two leagues ABC and XYZ. This is
the fact i want to capture. Since Bob played for the same team in 2
different leagues, I need to have two PLAYED_WITH_TEAM relations between
the same start (Bob) and end (Falcons) nodes.
I am using spring data and have the entities defined. I am able to create
2 such relationships but not more than two using spring data. i.e. if bob
played for the same team Falcons for another 3rd league, I am unable to
create that 3rd relation. I am not sure where the problem is. Below is my
code for creating the new relation. PlayedWith is a RelationshipEntity
with Player as the start node and Team as the end node.
private PlayedWith createPlayedWithRelation(League currentLeague, Team
team, Player p)
{
System.err.println("Creating PLAYED_WITH_TEAM relation between " +
team + " and " + p + " and " + currentLeague);
PlayedWith playedWith = template.createRelationshipBetween(p,
team, PlayedWith.class, "PLAYED_WITH_TEAM", true);
playedWith.setDuring(currentLeague.getStartDate());
playedWith.setInLeague(currentLeague);
playedWith.setPlayer(p);
playedWith.setTeam(team);
playedWith.setAsCaptain(p.isCaptain());
team.addPlayer(p);
template.save(playedWith);
return playedWith;
}
PlayedWith
@RelationshipEntity (type = "PLAYED_WITH_TEAM")
public class PlayedWith
{
@GraphId
private Long nodeId;
@StartNode
Player player;
@Fetch
@EndNode
Team team;
}
Let me know if there is an alternate way of storing this scenario.

No comments:

Post a Comment