要使用 neo4j-graphdatabase 独立服务器,我将 SDN 4.0.0.RC1 的依赖项添加到我的 pom 中:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>4.0.0.RC1</version>
<exclusions>
<exclusion>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
</exclusion>
</exclusions>
</dependency>
在我的应用程序中,我想管理家庭。Persons 作为 NodeEntities,relationtypes 作为 NodeEntities,family-relationships 作为RelationshipEntities。
为了保存节点或关系,我使用repository.save(T t) (repository extends GraphRepository<T>)
. 这适用于所有节点,但不适用于关系。
显式不起作用的代码:
Relation createdRelation = new Relation(typeName, from, to, getCurrentUsername());
createdRelation.setBegin(begin);
createdRelation.setEnd(end);
Relation relation = relationRepository.save(createdRelation);
我从 save(T t) 得到一个关系对象。但是,RelationshipEntity 并没有保存在图形数据库中。我的 Relation-Object 也没有任何 id。
关系实体类如下所示:
@RelationshipEntity(type = "RELATION")
public class Relation extends BaseMutableGraphEntity {
@Property
private String type;
@StartNode
private Person fromPerson;
@EndNode
private Person toPerson;
private Relation() {
}
...getters and setters...}
graph-id 保存在 BaseClass 中:
public abstract class BaseGraphEntity implements AuditEntity {
@GraphId
private Long id;
...with getters and setters...}
我现在的问题是:
如何使用 Spring Data Neo4j 4 RC1 保存我的关系实体?
关系实体是否有其他存储库?
PS:我试图将我的图形ID的位置更改为主要的RelationshipEntity,但它不起作用。