我在使用springboot集成neo4j进行关系插入时出现了些奇怪的问题:我在使用关系插入的时候关系会被识别成节点插入到数据库,会将关系里面的@StartNode和@EndNode注释的字段的字段名变为关系,效果图如下:
可以帮忙看下什么原因造成的吗
import lombok.Data;
import lombok.NoArgsConstructor;
import org.neo4j.ogm.annotation.StartNode;
import org.springframework.data.neo4j.core.schema.*;
@Node
@Data
@NoArgsConstructor
public class Person {
@Id
@GeneratedValue
private Long id;
@Property
private String name;
public Person(String name) {
this.name = name;
}
}
package org.example.entity;
import lombok.Data;
import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.RelationshipEntity;
import org.neo4j.ogm.annotation.StartNode;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Property;
@Data
@RelationshipEntity(type = "relation")
public class relation {
@Id
@GeneratedValue
private Long id;
@StartNode
private Person startNode;
@EndNode
private Person endNode;
@Property
private String type;
public relation(Person startNode, Person endNode, String type) {
this.startNode = startNode;
this.endNode = endNode;
this.type = type;
}
}
@Repository
public interface PersonRepository extends Neo4jRepository<Person, Long> {
}
@Repository
public interface relationRepository extends Neo4jRepository<relation,Long> {
}
@Test
public void test02() {
Person person1 = new Person("张");
Person person2 = new Person("李");
Person person3 = new Person("王");
Person person4 = new Person("赵");
relation relation = new relation(person1, person2, "relation");
relation relation1 = new relation(person1, person3, "relation");
relation relation2 = new relation(person1, person4, "relation");
List<relation> relations = new ArrayList<>();
relations.add(relation);
relations.add(relation1);
relations.add(relation2);
relationRepository.saveAll(relations);
}