我有一个mongo集合,可能包含三种类型的实体,我映射到java类型:
集合是使用父条目中的子节点的dbRefs来存储树状结构.
我没有在Spring参考文档中找到任何有关主题的信息,所以我在这里问:有没有办法使用Repository机制来处理可能包含不同类型对象的集合?
在一个集合中为不同类型声明几个存储库似乎不是一个好主意,因为当查询对象不是预期类型并且为抽象类创建一个所有可能类型继承似乎不起作用的存储库时,我总是很难处理.
说明我的意思:
/**
* This seems not safe
*/
public interface NodeRepository extends MongoRepository<Node, String> { }
public interface LeafType1Repository extends MongoRepository<LeafType1, String> { }
public interface LeafType2Repository extends MongoRepository<LeafType2, String> { }
/**
* This doesn't work at all
*/
public interface MyCollectionRepository extends MongoRepository<AbstractMyCollectionNode, String> { }
Run Code Online (Sandbox Code Playgroud)