Java-SDN 4-RC1:RelationRepository.save(relationshipEntity)不在图形中保存RelationshipEntities
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java-SDN 4-RC1:RelationRepository.save(relationshipEntity)不在图形中保存RelationshipEntities,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2275字,纯文字阅读大概需要4分钟。
内容图文
![Java-SDN 4-RC1:RelationRepository.save(relationshipEntity)不在图形中保存RelationshipEntities](/upload/InfoBanner/zyjiaocheng/681/ceab9924299c47689e17fa7ca5f6d026.jpg)
要使用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>
在我的申请中,我想管理家庭.人员作为节点实体,关系类型作为节点实体,家庭关系作为关系实体.
为了保存节点或关系,我使用了repository.save(T t)(存储库扩展了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不会持久保存在graphdatabase中.另外,我的关系对象没有任何ID.
RelationshipEntity类如下所示:
@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保存我的RelationshipEntities?
是否有其他用于RelationshipEntities的存储库?
P.S .:我试图将我的图形ID的位置更改为主要的RelationshipEntity,但是它不起作用.
解决方法:
我也遇到了这个怪癖,并且能够通过以下方式保持我的关系:
>在@StartNode实体上设置您的关系
>保存@StartNode实体或@RelationshipEntity,看来关键是必须先在@StartNode上设置对象
因此,在您的示例中,您将必须执行以下操作:
Relation createdRelation = new Relation(typeName, from, to, getCurrentUsername());
createdRelation.setBegin(begin);
createdRelation.setEnd(end);
begin.setRelation(createdRelation);
Relation relation = relationRepository.save(createdRelation);
所有人都说过,我不得不承认我不是100%知道这是否是应该完成的方式,因为在当前文档修订版中尚不清楚,但它似乎确实是SDN4示例测试中采用的方法:
https://github.com/spring-projects/spring-data-neo4j/blob/4.0.x/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/movies/MoviesIntegrationTest.java(请参阅findOneShouldConsiderTheEntityType)
内容总结
以上是互联网集市为您收集整理的Java-SDN 4-RC1:RelationRepository.save(relationshipEntity)不在图形中保存RelationshipEntities全部内容,希望文章能够帮你解决Java-SDN 4-RC1:RelationRepository.save(relationshipEntity)不在图形中保存RelationshipEntities所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。