SDN 4 不与属性建立关系
SDN 4 doesn't create relationship with properties
我是 Neo4J 的新手。我建立了一个使用 spring-data-neo4j(4.0.0.BUILD-SNAPSHOT - 版本),spring-boot(1.2.3.RELEASE - 版本)并成功的项目创建节点实体,向节点实体添加属性并添加关系。它工作正常。现在我想为关系创建属性。我用sdn4大学作为参考,这里是link https://github.com/neo4j-examples/sdn4-university .
我想为关系 PLAY_MATCH 创建一个名为 "challengedBy" 的 属性(开始节点是 Match,结束节点是 Player)。你可以看看下面class.
@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.
}
我认为你在玩家端节点内也有比赛关系。如果在player节点中注释下面的代码。它应该工作。我还附上了一个 json 示例,以从匹配 URL (/api/match) 中的 UI 传递,而不是 (/api/playmatch)
@Relationship(type="PLAY_MATCH")
private PlayMatch playMatch;
public PlayMatch getPlayMatch() {
return playMatch;
}
public void setPlayMatch(PlayMatch playMatch) {
this.playMatch = playMatch;
}
样本JSON
{
"type": "typename",
"status": "statusname",
"createdTime": 1435928223021,
"noOfGames": 5,
"noOfPoints": 19,
"playMatch": {"challengedBy" : "John", "player1" : {"id":732}, "match":{"type": "typename",
"status": "statusname",
"createdTime": 1435928223021,
"noOfGames": 5,
"noOfPoints": 19}}
}
这应该创建一个新的比赛,并与 属性 challengedBy 建立新的关系到一个 ID 为 732 的现有玩家节点。
检查一下,如果有效请告诉我。
我是 Neo4J 的新手。我建立了一个使用 spring-data-neo4j(4.0.0.BUILD-SNAPSHOT - 版本),spring-boot(1.2.3.RELEASE - 版本)并成功的项目创建节点实体,向节点实体添加属性并添加关系。它工作正常。现在我想为关系创建属性。我用sdn4大学作为参考,这里是link https://github.com/neo4j-examples/sdn4-university .
我想为关系 PLAY_MATCH 创建一个名为 "challengedBy" 的 属性(开始节点是 Match,结束节点是 Player)。你可以看看下面class.
@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.
}
我认为你在玩家端节点内也有比赛关系。如果在player节点中注释下面的代码。它应该工作。我还附上了一个 json 示例,以从匹配 URL (/api/match) 中的 UI 传递,而不是 (/api/playmatch)
@Relationship(type="PLAY_MATCH")
private PlayMatch playMatch;
public PlayMatch getPlayMatch() {
return playMatch;
}
public void setPlayMatch(PlayMatch playMatch) {
this.playMatch = playMatch;
}
样本JSON
{
"type": "typename",
"status": "statusname",
"createdTime": 1435928223021,
"noOfGames": 5,
"noOfPoints": 19,
"playMatch": {"challengedBy" : "John", "player1" : {"id":732}, "match":{"type": "typename",
"status": "statusname",
"createdTime": 1435928223021,
"noOfGames": 5,
"noOfPoints": 19}}
}
这应该创建一个新的比赛,并与 属性 challengedBy 建立新的关系到一个 ID 为 732 的现有玩家节点。
检查一下,如果有效请告诉我。