在数据库更新后的模型类问题,

huangapple go评论68阅读模式
英文:

Issue with model classes after database updates,

问题

我已经创建了一个应用程序,可以在数据库上执行数据操作。现在有一个条件,用户在数据库中创建了一个新表(通过前端创建),但由于缺少模型类,该表无法访问,所以在JAVA中是否有任何类型的框架可以在没有相应模型类依赖的情况下执行这种类型的操作。

简而言之,是否有任何框架可以处理所有类型的数据定义语言(DDL)和数据操作语言(DML),而无需模型类依赖?
我知道这个问题有点愚蠢。

英文:

I have created one application which can able to perform a DML operation on database. Now there is one condition the user created new table in that database(by using front-end) but that table is not accessible due to model class is not available, so there is any type of Framework in JAVA which can able to perform this type of operations without respective model classes dependencies.

In short there is any framework which handle all types of DLL and DML operation without model classes?
i know its stupid question.

答案1

得分: 2

我将为您提供关于您在问题中标记的一些API的答案,以及JDBC:

JPA

JPA在编译时(在加载实体时)需要一个模型,因此它与像您这样的临时模型不太兼容。当然,您可以使用运行时Java编译并动态加载那些运行时生成的实体,但这似乎相当复杂。

jOOQ

jOOQ可以按照教程中所述的方式工作。您可以使用jOOQ:

在jOOQ中,生成的代码是完全可选的,为客户端代码增加了额外的类型安全性,但您不必使用它。所有DDL和DML语句都可以使用临时标识符,甚至可以使用纯SQL模板来表示。

JDBC

在使用Java/Spring等时,您始终可以借助JDBC,这是大多数上述API背后使用的较低级别的API。在Spring中,还有一个基于JDBC的薄型API,称为JdbcTemplate,它使使用JDBC更加方便。

(免责声明:我在jOOQ所在公司工作)

英文:

I'll provide an answer for a few APIs that you've tagged your question with, plus JDBC:

JPA

JPA requires a model at compile time (technically at the time when you load the entities), so it doesn't work well with ad-hoc models like yours. You could, of course, use runtime Java compilation and load those runtime generated entities dynamically, but that seems quite complicated.

jOOQ

jOOQ can work that way as stated e.g. in the tutorial. You can use jOOQ:

In jOOQ, generated code is completely optional, adding additional type safety to your client code, but you don't have to use it. All DDL and DML statements can be expressed with ad-hoc identifiers, or even plain SQL templating.

JDBC

When using Java/Spring/etc. you can always resort to using JDBC, the lower level API that is used by most of the above APIs behind the scenes. In Spring, there's also a thin API on top of JDBC called JdbcTemplate, which makes using JDBC a bit more convenient.

(Disclaimer: I work for the company behind jOOQ)

huangapple
  • 本文由 发表于 2020年5月30日 23:16:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/62104489.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定