具有 DynamoDB 和 MySQL 双数据源的 Spring Data/JPA 存储库

2022-01-15 00:00:00 amazon-dynamodb spring java jpa spring-data

我熟悉如何让 Spring 通过多个持久性单元和多个 entityManagerFactoryBean 实现动态处理多个数据源,但我正在努力解决的是如何使用 MySQL 方言和 DynamoDB 方言在同一个 spring 配置中,通过 spring-config xml 文件.

I'm familiar with how to make Spring handle multiple datasources dynamically via multiple persistence-units and multiple entityManagerFactoryBean implementations but what I'm struggling with is how to have a MySQL dialect and a DynamoDB dialect from within the same spring configuration, via spring-config xml files.

工作模式如下:

[来自某个端点的数据 POJO] ->将 POJO 持久化到 DynamoDB 中,检索该对象的 UUID(业务键作为 POJO 上的字段)->将 UUID 作为复合键(没有参照完整性,它只是另一列)保存到 MySQL 数据库[与其他相关映射实体].

[data POJO in, from some endpoint] -> Persist POJO into DynamoDB, retrieving the UUID of that object (business key as field on POJO) -> Persist UUID as a compound key (no referential integrity, it's just another column) into MySQL Database [with other related mapped entities].

我正在为如何将 DynamoDB 实例添加到 Spring 配置文件中来实现这一点而苦苦挣扎.

I'm struggling with quite how on earth to go about adding the DynamoDB instance into the Spring configuration files to achieve this.

不管怎样,相关的存储库将位于单独的包中.

For what it's worth, the related repositories are going to be in separate packages.

任何 10 人的首发将不胜感激!我已经进行了一些搜索,但所有 DynamoDB 映射器框架似乎都处于更高的水平 - 我在这里错过了什么吗?我一直在查看 Spring-Data DynamoDB 但仍然无法建立联系配置文件和 Dynamo.

Any starters for 10 would be gratefully received! I've done some searching but all DynamoDB mapper frameworks seem to be at a much higher level - have I missed something here? I've been looking at Spring-Data DynamoDB but still can't make the link between the configuration file and Dynamo.

提前致谢,

一个.

========= 更新思维=========

========= UPDATE IN THINKING =========

我认为我做错了.通过更多地挖掘样本,进行本地集成测试 [纯 dynamodb],我认为不可能将 DynamoDB 用作 EntityManager Factory 实现的一部分:为此,我认为我将不得不创造"我自己的存储库实现调用 Dynamo 的映射器和 AWS 连接帮助器类等,而不是使用任何 JPA spring 提供的代码.

I think I've gone about this the wrong way. From digging around the samples a lot more, doing a local integration test [pure dynamodb], I don't think it's possible to use DynamoDB as part of an EntityManager Factory implementation: to that end, I think I'm going to have to "create" my own repository implementations that call out to the mapper and AWS connection helper classes etc. for Dynamo, rather than using any of the JPA spring-provided code.

除非有人可以推荐/建议否则?

Unless anyone can recommend/suggest otherwise?

推荐答案

问题结束 - 经过大量调查,唯一真正的方法是引入自己对存储库和基于 DAO 的实现的解释.

Question closed - after much investiation the only real way to do it is to introduce ones own interpretation of a repository and DAO-based implementation.

然而,有一个有趣的项目,Spring Data Dynamodb.看起来很有趣,但还没有为企业生产版本做好准备.

There is one interesting project, however, Spring Data Dynamodb. Looks interesting but not quite ready for Enterprise Production release.

相关文章