简体   繁体   English

Spring-Data-Neo4J类多态性

[英]Spring-Data-Neo4J Class Polymorphism

SDN v3.0.0 RELEASE Neo4j Community 2.0.1 SDN v3.0.0发布Neo4j社区2.0.1

I'm having a bit of an issue with regards to inheritance and collections. 关于继承和集合,我遇到了一个问题。 Perhaps someone could assist with the matter. 也许有人可以协助解决此事。 I basically have the following structure. 我基本上具有以下结构。

public abstract class Graphic;

public class Shape1 extends Graphic;

public class Shape2 extends Graphic;

public class Shape3 extends Graphic;

public class Overlay {

    Set<Graphic> graphics;

}

public interface GraphicsRepository extends GraphRepository<Graphic>{}

I can persist the graphics using the graphic repository and all the various attributes are stored correctly based on the concrete classes. 我可以使用图形存储库持久保存图形,并且根据具体类正确存储所有各种属性。 I can query and get individual graphics with the correct attributes, and do various things associate with the classes in the neo4j "portal" environment. 我可以查询并获得具有正确属性的单个图形,并可以执行与neo4j“门户”环境中的类相关的各种操作。 But when i do a retrieve on the overlay i only ever get the base class Graphic as the class type within the collection and casting does not work. 但是当我在覆盖层上进行检索时,我只能得到基类Graphic,因为集合和转换中的类类型不起作用。 I could be overlooking something or just not doing something correctly, but figured i would post and see if there was anything that someone could suggest. 我可能会忽略某件事,或者只是做某件事不正确,但我想我会发布并查看是否有人可以提出建议。 I've searched google and stack overflow and have only ever found similar issues where it was the main class and never a internal collection of objects. 我已经搜索了谷歌和堆栈溢出,只发现类似的问题,它是主要的类,从来没有内部对象的集合。

Also, when i remove abstract from the Graphic class i get the same results⦠All items in the Overlay graphics set are of type Graphic. 另外,当我从Graphic类中删除摘要时,我得到相同的结果……Overlay图形集中的所有项目均为Graphic类型。 And adding @TypeAlias does not seem to help. 并且添加@TypeAlias似乎无济于事。

Thanks 谢谢

Ok, i found the issue… kind of feel foolish but i forgot to put @Fetch on the graphic collection. 好的,我发现了这个问题……有点愚蠢,但我忘记将@Fetch放在图形集合中。 Strangely enough it does retrieve graphic objects but they are all of type Graphic. 奇怪的是,它确实检索了图形对象,但是它们都是Graphic类型。 When i added fetch to the collection, the collection items were retrieved with the correct type. 当我将fetch添加到集合中时,将使用正确的类型检索集合项。

Actually it should use the type stored in the graph to construct the entity, ie the most concrete type (in SDN 3.0.1 it is prepended by a "_", so should be "_Shape1" etc.) 实际上,它应该使用存储在图中的类型来构造实体,即最具体的类型(在SDN 3.0.1中,它以“ _”开头,因此应为“ _Shape1”等)。

Can you check the labels of the nodes in the graph? 您可以检查图中节点的标签吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM