[英]Relationship not saved in SDN 6 (Spring data neo4j)
Hello have problems with saving relation ships with NEO4J and Spring, I can save relationships when I don't use a class with @RelationProperties
, but whenever I want to use that class the relationships are not even created.您好,在保存与 NEO4J 和 Spring 的关系时遇到问题,当我不使用带有 @RelationProperties 的
@RelationProperties
时,我可以保存关系,但是每当我想使用 class 时,甚至都不会创建关系。
I am using Neo4j 4.3.7-community edition in a docker container And in my pom.xml i have我在 docker 容器中使用 Neo4j 4.3.7-社区版 在我的 pom.xml 中我有
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>6.1.5</version>
</dependency>
I want to do something like this Image我想做这样的事情
I have this bit of code:我有这段代码:
starting node起始节点
...
@Relationship(type = "VISITS",direction = Relationship.Direction.OUTGOING)
public Set<Visits> visits;
public void visitPOI(Visits visit) {
if(visits == null) {
visits = new HashSet<>();
}
visits.add(visit);
}
...
My relation我的关系
@RelationshipProperties
public class Visits {
@Id @GeneratedValue
private long id;
@Property private String description;
@TargetNode private PointOfInterest poi;
public Visits(String description, PointOfInterest p){
this.description = description;
this.poi = p;
}
...
and the destination node和目标节点
...
@Node
public class PointOfInterest {
@Id @GeneratedValue(generatorClass = UUIDStringGenerator.class)
private String id;
@Property private String name;
@Property private double lat;
@Property private double lng;
public PointOfInterest() { }
//getters and setters
...
And this in a service这在服务中
...
public void saveRelation(String username, Visits v ){
User u = userRepository.findByUserName(username);
Optional<PointOfInterest> poi = pointOfInterestRepository.findById(v.getPoi().getId());
v.setPoi(poi.get());
u.visitPOI(v);
userRepository.save(u);
}
...
and the JSON I post和我发布的 JSON
{
"description":"Nice trip",
"poi":{
"id":"Uster"
}
}
Use @RelationshipId
on id field of @RelationshipProperties
as follow在
@RelationshipId
的 id 字段上使用@RelationshipProperties
如下
@RelationshipProperties
public class Visits {
@RelationshipId
private long id;
@Property private String description;
.....
}
I had the same issue with persisting relationship properties using @RelationshipProperty
annotated class. Finally, I discovered that the issue is due to the implicit conversion between long and Long.我在使用
@RelationshipProperty
注释 class 持久化关系属性时遇到了同样的问题。最后,我发现问题是由于 long 和 Long 之间的隐式转换引起的。 Changing @RelationshipId private long id;
更改
@RelationshipId private long id;
to @RelationshipId private Long id;
到
@RelationshipId private Long id;
inside the @RelationshipProperty
annotated class will do the trick.在
@RelationshipProperty
注释为 class 就可以了。 This appears to be a bug in SDN, it should report an error instead.这似乎是 SDN 中的一个错误,它应该报告错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.