无法在两个节点之间创建两个以上的相同关系 [英] unable to create more than 2 same relations between two nodes
问题描述
花了几天时间试图弄清楚为什么它不起作用.我的模型是Player-[:PLAYED_WITH_TEAM]->team-[:CONTESTED_IN]->league
.这种关系的几个实例如下
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
鲍勃在ABC和XYZ两个联赛中为同一支猎鹰"队效力.这是我要捕获的事实.由于鲍勃在2个不同的联赛中为同一支球队效力,因此我需要在相同的起点(Bob)和终点(Falcons)之间建立两个PLAYED_WITH_TEAM关系.
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.
我正在使用spring数据并已定义实体.我可以使用spring数据创建2个这样的关系,但最多可以创建2个这样的关系.也就是说,如果鲍勃在同一支猎鹰队效力过另一个第3联赛,那么我将无法建立第3关系.我不确定问题出在哪里.下面是我用于创建新关系的代码. PlayedWith是一个RelationshipEntity
,其中Player
作为开始节点,Team
作为结束节点.
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
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.
推荐答案
实际上,鲍勃和猎鹰之间只有一个:PLAYED_WITH_TEAM关系. 您确定要获取鲍勃和猎鹰之间的:PLAYED_WITH_TEAM关系数量正确吗?
Actually there should only be one :PLAYED_WITH_TEAM relationship between bob and the falcons. Are you sure that you query is right for getting the amount of :PLAYED_WITH_TEAM relationships between Bob and the falcons?
从SDN参考文档中:
注意
Spring Data Neo4j默认情况下确保只有一个 给定类型在任何两个给定实体之间的关系.这个可以 通过使用createRelationshipBetween()方法来规避 存储库或实体上的allowDuplicates参数.
Spring Data Neo4j ensures by default that there is only one relationship of a given type between any two given entities. This can be circumvented by using the createRelationshipBetween() method with the allowDuplicates parameter on repositories or entities.
这篇关于无法在两个节点之间创建两个以上的相同关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!