花了多天的時間試圖找出爲什麼這不起作用。我的模特是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