Neo4j-Ogm用于动态域对象模型 [英] Neo4j-Ogm for dynamic domain object model
问题描述
我已开始在应用程序内部使用Neo4j-ogm,它的作用就像固定对象域模型的魅力.当我知道哪个节点类型连接到具有已知类型的另一个节点时,可以轻松地映射它. 但是,在我看来,Neo4j图形数据库的多功能性还可以与无类型(或动态)域模型一起使用,并且我在概念上存在问题,难以理解如何使用Neo4j-ogm实现它.
I've started to use Neo4j-ogm inside my application and it works like charm for fixed object domain model. When I know which node type connected to another node with known type - it can be easily mapped. However, in my opinion versitality of Neo4j graph database is also in an ability to work with un-typed (or dynamic) domain models and I'm having conceptual problem to understand how to achieve it with Neo4j-ogm.
让我用一个例子来描述我的问题.
Let me describe my problem with an example.
我有域对象,例如:消息和功能.消息可以具有多个功能,而一个功能可以是许多消息的一部分.用Neo4j-ogm映射完全可以.
I have domain objects like: Message and Feature. Where Message can have multiple features and a Feature can be a part of many messages. It is completely ok to map with Neo4j-ogm.
然后,如果用户要将消息与某些Task节点类型相关联或将其引用为某些Contact节点类型该怎么办?在我的应用程序中,可能在各种类型的节点之间建立大型(但有限)连接集.因此,我希望能够从特定节点获取所有类型的连接,而不管此连接类型或endNode类型如何?
Then what if user want to relate the message to some Task node type or refer it to some Contact node type ? In my application it is possible to have large (but limited) set of connection between nodes of various types. So I would like to be able to get all types of connections from a particular node, regardless of this connection types or endNode types?
我当然可以使用cypher来创建这样的连接:
Of course I can use cypher to create connections like this:
MATCH ($2911) WHERE id($2911)={$2911} MATCH ($2912) WHERE id($2912)={$2912} MERGE ($2911)-[_0:`part_of` {$aid} ]->($2912) RETURN id(_0) AS _0
但是当我开始执行此操作时-我需要一种方法来自己将查询结果与关系实体进行相互转换.
but when I'm starting doing this - I would need a way how to convert results of this queries to and from relational entities myself.
是否有使用Neo4j-ogm做到这一点的完整方法.可能可以创建一个全面的类型层次结构,或者可以将Neo4j-ogm一起用于固定和动态域对象模型的某种方法.
Is there a gracefull way to do this using Neo4j-ogm. May be it is possible to create a comprehansive type heirarchy or something which will allow to use Neo4j-ogm together for fixed and dynamic domain object models.
先谢谢您.
推荐答案
Neo4j OGM支持固定类型的层次结构,因此,如果您能够在这样的层次结构中表示您的域,则应该能够从单一实体.这意味着末端节点也必须在此层次结构中表示.
A fixed type hierarchy is supported by Neo4j OGM so if you are able to represent your domain in such a hierarchy, you should be able to fetch all connections from a single entity. This means that the end nodes must be also represented in this hierarchy.
当前版本不支持运行时多态性-尽管尚待讨论,所以根据运行方式的不同,它可能会成为将来的版本.
Run time polymorphism is not supported in the current version- it's up for discussion though, so depending on how it goes, it might make it to a future release.
这篇关于Neo4j-Ogm用于动态域对象模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!