标题翻译
Dynamic Model Creation with Spring Data JPA
问题
我最近在开发一个ETL工具,一旦提供了两个连接字符串,它会从第一个数据库中读取数据,进行转换,并将数据持久化到第二个数据库中。
我正在使用Spring Data JPA,但我在某个特定点遇到了困难:
我的问题是,当我连接到第一个数据库时,我必须将数据转换为Java对象。在一个简单的项目中,可以通过用Entity
注解的模型类来实现。但在这个过程中,运行时环境并不知道它将遇到哪些表。例如,不可能知道数据库中是否包含Actor
或Movies
表,以及在这些表中,列和它们的类型将保持未知。
我必须以一种通用的方式来处理,但目前我甚至无法创建相应的模型类。是否有一种方式可以仅使用Spring Data JPA
来推断表和表结构?
附注:我正努力保持简单,并且如果找不到解决方案,我会转而使用Spring JDBC
。
英文翻译
I'm working on an ETL tool recently, which, once given two connection strings, reads data from the first database, do transformations and persists them to the second database.
I'm using Spring Data JPA, but I'm stuck in a certain point:
My problem is that, when I connect to the first database, I must convert them into Java objects. In a simple project this is done by model classes annotated by Entity
. But in this process the runtime environment doesn't know what tables it will encounter. For example, it is impossible to know if the database consists an Actor
or Movies
table -or both- and within those tables, the columns and their types will remain unknown.
I must do it in a generic way, but at the moment I can't even create corresponding Model classes. Is there a way of inferring tables and table structures just using Spring Data JPA
?
P.s. I am trying to keep things simple and will go for Spring JDBC
if I can't find a solution.
专注分享java语言的经验与见解,让所有开发者获益!
评论