花了多天的时间试图找出为什么这不起作用。我的模特是Player-[:PLAYED_WITH_TEAM]->team-[:CONTESTED_IN]->league
。这种关系的几个例子如下:无法在两个节点之间创建超过2个相同的关系
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
鲍勃在两个联赛ABC和XYZ效力于同一支球队“猎鹰”。这是我想要捕捉的事实。由于Bob在2个不同的联赛中为同一个球队效力,我需要在同一起始(Bob)和结束(Falcons)节点之间有两个PLAYED_WITH_TEAM关系。
我使用弹簧数据并定义了实体。我能够使用弹簧数据创建2个这样的关系但不超过两个。即如果鲍勃在同一队猎鹰队为另一个第三联赛效力,我无法创造第三关系。我不确定问题出在哪里。以下是我创建新关系的代码。 PlayedWith是RelationshipEntity
,Player
作为起始节点,Team
作为终止节点。
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;
}
让我知道是否有存储这种情况下的替代方法。
这是我的初始模型,但这种方法有一个缺点。你怎么能找到只玩过XYZ联盟的猎鹰队员?玩家可能不会玩所有的联赛。 –
然后你需要从球员到联盟的其他关系。 – h3nrik