如何在SDN 4.0中CRUD @RelationshipEntity [英] How to CRUD @RelationshipEntity in SDN 4.0

查看:479
本文介绍了如何在SDN 4.0中CRUD @RelationshipEntity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我有一个丰富的关系实体

If I have a rich relationship entity, for example

@NodeEntity
public class Actor {
    Long id;
    private Role playedIn;
}

@RelationshipEntity(type="PLAYED_IN")
public class Role {
    @GraphId   private Long relationshipId;
    @Property  private String title;
    @StartNode private Actor actor;
    @EndNode   private Movie movie;
}

@NodeEntity
public class Movie {
    private Long id;
    private String title;
}

要对这两个@NodeEntity进行CRUD,只需简单地分别创建一个@Repository

To CRUD both @NodeEntity, just simply create a @Repository each, for example

@Repository
public interface ActorRepository extends GraphRepository<Actor>{

}

做CRUD很简单

@Autowired
ActorRepository actorRepository

actorRepository.save(new Actor(....))

我的问题是,我们如何为@RelationshipEntity Role做CRUD?

My question is, how we do CRUD for the @RelationshipEntity Role ?

我们是否为Role创建一个@Repository? (我尝试过,它不起作用)

Are we create one @Repository for Role? (I tried, it is not working)

推荐答案

MicTech是正确的.

MicTech is right.

RelationshipEntity由图中的边缘而不是节点表示,并且当前Repository实现仅适用于可以作为节点持久化的对象.这不会给您造成任何问题.

A RelationshipEntity is represented by an edge in the graph, not a node, and currently Repository implementations are applicable only for objects which can be persisted as nodes. This should not cause you any problems.

OGM将持久保存您显式保存的对象中的所有可到达对象(除非您告诉它不这样做).这种行为意味着,无论您保存NodeEntity还是当它们均由RelationshipEntity显式表示或由NodeEntity实例之间的直接引用隐式表示时,连接的对象之间的边缘都会自动创建/更新.

The OGM will persist all reachable objects from the one you explicitly save (unless you tell it not to). This behaviour means that edges between connected objects are created/updated automatically whenever you save a NodeEntity, regardless of whether those edges are explicitly represented by a RelationshipEntity or implicitly by direct references between NodeEntity instances.

与使用SDN的存储库方法时相比,OGM的会话对象的限制要稍宽松一些,因为您可以调用

The OGM's session object is slightly less restrictive than when using SDN's Repository methods in that you can invoke

session.save(...)

在标注为RelationshipEntity的对象上,它将按您期望的那样运行.但是,实际上没有必要这样做:保存RelationshipEntity的开始或结束节点将确保图形正确保留.

on an object annotated as a RelationshipEntity, and it will do as you expect. But, there is actually no need to do this: saving either the start or end node of a RelationshipEntity will ensure the graph is correctly persisted.

这篇关于如何在SDN 4.0中CRUD @RelationshipEntity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆