I'm using the mongodb-customer-service-data examples (available at https://github.com/SpringSource/spring-data-document-examples).
我正在使用mongodb-customer-service-data示例(可从https://github.com/SpringSource/spring-data-document-examples获得)。
The example uses @RelatedDocument to associate domain objects across databases. It allows storing and updating objects well enough.
该示例使用@RelatedDocument跨数据库关联域对象。它允许足够好地存储和更新对象。
However, I want to do a Query that has Criteria against both the JPA database (in the example HSQLDB) and MongoDB.
但是,我想做一个对JPA数据库(在示例HSQLDB中)和MongoDB都有Criteria的Query。
Is this even possible? Is there any example anywhere that proves that it is possible?
这有可能吗?有没有任何例子可以证明它是可能的?
Comments not directly related to the issue:
评论与该问题没有直接关系:
My use case is that our application is an Oracle DB, but we are now starting to receive semi-structured data. The JPA Entities are filterable by a user within certain constraints, but we'd like to expand this capability to the semi-structured data.
我的用例是我们的应用程序是Oracle DB,但我们现在开始接收半结构化数据。 JPA实体可由用户在某些约束条件下过滤,但我们希望将此功能扩展为半结构化数据。
There also seems to be competing technologies QueryDSL and EclipseLink, but I can't find anything about doing queries across databases.
似乎还有竞争技术QueryDSL和EclipseLink,但我找不到任何关于跨数据库进行查询的事情。
In JPA, it doesn't appear to be possible to do cross database queries because there are different PersistanceUnits that are associated with each database. However, mongodb cross-store seems to negate this particular problem.
在JPA中,似乎不可能进行跨数据库查询,因为存在与每个数据库关联的不同PersistanceUnits。然而,mongodb跨店似乎否定了这个特殊问题。
1 个解决方案
#1
0
I never used Spring Data JPA, but if JPA isn't capable of doing this I doubt that Spring Data will offer such capabilities.
I don't know what you understand by mongodb cross-store. So I'll explain shortly what mongodb can and can't do.
我从未使用过Spring Data JPA,但如果JPA无法做到这一点,我怀疑Spring Data会提供这样的功能。我不知道你对mongodb跨店的理解。所以我很快就会解释一下mongodb可以做什么和不能做什么。
With mongodb you can't have queries across multiple collections (tables), so you can't do join with plain mongodb. So @RelatedDocument is a feature which Spring Data offers. Related documents may be either embedded (don't know if Spring Data supports this) or may be some simple DBRef to a document within a different collection (and database). With DBRef you can only query on @RelatedDocument fields like _id, collection and database, but none of the actual referenced documents property.
使用mongodb,您无法跨多个集合(表)进行查询,因此您无法使用普通mongodb进行连接。所以@RelatedDocument是Spring Data提供的一个功能。相关文档可以是嵌入的(不知道Spring Data是否支持),也可以是不同集合(和数据库)中的文档的简单DBRef。使用DBRef,您只能查询_id,集合和数据库等@RelatedDocument字段,但不能查询实际引用的文档属性。
This said mongodb doesn't allow to search cross database in a single query, as you can't do queries across collections so you can't do this against databases either. The only cross-store functionality you have, is for sharded collections. With this you have you collection distributed across multiple nodes through a shardkey. MongoDB may need to query across all collection shards to fulfill your query. But beside this, what I wouldn't call actually a cross-database function, you have no such capabilities.
这说明mongodb不允许在单个查询中搜索跨数据库,因为您无法跨集合进行查询,因此您也无法对数据库执行此操作。您拥有的唯一跨店功能适用于分片集合。通过这个,您可以通过shardkey在多个节点上分布集合。 MongoDB可能需要跨所有集合分片进行查询以完成您的查询。但除此之外,我不会称之为跨数据库功能,你没有这样的能力。
If this doesn't help, please explain in more detail what you want todo.
如果这没有帮助,请更详细地解释您想要的东西。
#1
0
I never used Spring Data JPA, but if JPA isn't capable of doing this I doubt that Spring Data will offer such capabilities.
I don't know what you understand by mongodb cross-store. So I'll explain shortly what mongodb can and can't do.
我从未使用过Spring Data JPA,但如果JPA无法做到这一点,我怀疑Spring Data会提供这样的功能。我不知道你对mongodb跨店的理解。所以我很快就会解释一下mongodb可以做什么和不能做什么。
With mongodb you can't have queries across multiple collections (tables), so you can't do join with plain mongodb. So @RelatedDocument is a feature which Spring Data offers. Related documents may be either embedded (don't know if Spring Data supports this) or may be some simple DBRef to a document within a different collection (and database). With DBRef you can only query on @RelatedDocument fields like _id, collection and database, but none of the actual referenced documents property.
使用mongodb,您无法跨多个集合(表)进行查询,因此您无法使用普通mongodb进行连接。所以@RelatedDocument是Spring Data提供的一个功能。相关文档可以是嵌入的(不知道Spring Data是否支持),也可以是不同集合(和数据库)中的文档的简单DBRef。使用DBRef,您只能查询_id,集合和数据库等@RelatedDocument字段,但不能查询实际引用的文档属性。
This said mongodb doesn't allow to search cross database in a single query, as you can't do queries across collections so you can't do this against databases either. The only cross-store functionality you have, is for sharded collections. With this you have you collection distributed across multiple nodes through a shardkey. MongoDB may need to query across all collection shards to fulfill your query. But beside this, what I wouldn't call actually a cross-database function, you have no such capabilities.
这说明mongodb不允许在单个查询中搜索跨数据库,因为您无法跨集合进行查询,因此您也无法对数据库执行此操作。您拥有的唯一跨店功能适用于分片集合。通过这个,您可以通过shardkey在多个节点上分布集合。 MongoDB可能需要跨所有集合分片进行查询以完成您的查询。但除此之外,我不会称之为跨数据库功能,你没有这样的能力。
If this doesn't help, please explain in more detail what you want todo.
如果这没有帮助,请更详细地解释您想要的东西。