我是Neo4J的新手。我已經構建了一個使用spring-data-neo4j(4.0.0.BUILD-SNAPSHOT-版本),spring-boot(1.2.3.RELEASE-版本)併成功創建節點實體的項目,爲節點實體添加屬性並添加關係。它工作正常。現在我想創建關係的屬性。我用sdn4大學作爲參考,這裏是鏈接https://github.com/neo4j-examples/sdn4-university。SDN 4不會與屬性建立關係
我想爲關係PLAY_MATCH創建一個名爲「challengedBy」的屬性(起始節點是匹配,結束節點是播放器)。你可以看看下面的課。
@RelationshipEntity(type = "PLAY_MATCH")
public class PlayMatch extends Entity {
//Entity is a class with the id property for the node/relationship
@Property
private String challengedBy;
@StartNode
private Match match;
@EndNode
private Player player1;
}
我在項目/ api/playmatch中創建了一個控制器,只創建匹配和玩家之間的關係。所以當我傳遞一個現有的匹配節點和一個玩家節點的值時,關係根本就不會創建。
任何幫助將不勝感激..
PlayMatch代碼
@RelationshipEntity(type = "PLAY_MATCH")
public class PlayMatch extends Entity{
@Property
private String challengedBy;
@StartNode
private Match match;
@EndNode
private Player player1;
public PlayMatch() {
}
public PlayMatch(String challengedBy, Match match,
Player player1) {
super();
this.challengedBy = challengedBy;
this.match = match;
this.player1 = player1;
}
// after this i have getters & setters and toString method for above fields.
}
匹配代碼是
@NodeEntity(label = "Match")
public class Match extends Entity {
private String createdBy;
private Long createdTime;
private String status;
private int noOfGames;
private int noOfPoints;
private String type;
private Long date;
@Relationship(type="PLAY_MATCH",direction= Relationship.UNDIRECTED)
private PlayMatch playMatch;
public Match() {
}
public Match(String createdBy, Long createdTime, String status,
int noOfGames, int noOfPoints, String type, Long date) {
super();
this.createdBy = createdBy;
this.createdTime = createdTime;
this.status = status;
this.noOfGames = noOfGames;
this.noOfPoints = noOfPoints;
this.type = type;
this.date = date;
}
public PlayMatch getPlayMatch() {
return playMatch;
}
public void setPlayMatch(PlayMatch playMatch) {
this.playMatch = playMatch;
}
// after this i have getters & setters and toString method for above fields.
}
播放器代碼
@NodeEntity(label = "Player")
public class Player extends Entity {
private String address;
private String preferredSport;
private float height;
private float weight;
private String phone;
private String photo;
@Relationship(type="PLAY_MATCH")
private PlayMatch playMatch;
public PlayMatch getPlayMatch() {
return playMatch;
}
public void setPlayMatch(PlayMatch playMatch) {
this.playMatch = playMatch;
}
public Player() {
}
public Player(String address, String preferredSport, float height,
float weight, String phone, String photo) {
super();
this.address = address;
this.preferredSport = preferredSport;
this.height = height;
this.weight = weight;
this.phone = phone;
this.photo = photo;
}
// after this i have getters & setters and toString method for above fields.
}
你是如何創建PlayMatch的,你能分享代碼嗎? Match和Player也是什麼樣子? – Luanne
@Luanne我已更新帖子,請看看它,並讓我知道更新,在此先感謝 – Aditya
看起來很好,這是什麼問題?您是否在保存之前在播放器上設置了PlayMatch並匹配? – Luanne