我是 Neo4J 的新手。我已经建立了一个使用 spring-data-neo4j (4.0.0.BUILD-SNAPSHOT - 版本),spring-boot (1.2.3.RELEASE - 版本)的项目并成功创建节点实体,向节点实体添加属性并添加关系。它工作正常。现在我想为关系创建属性。我使用了 sdn4 大学作为参考,这里是链接https://github.com/neo4j-examples/sdn4-university。
我想为关系 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.
}