H2数据库不支持schema.package.function结构。

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

H2 Database doesn’t support schema.package.function structure

问题

在我的项目中,我们使用 Oracle 数据库作为主要的应用数据库,并且使用 H2 作为内存数据库,仅用于运行集成测试用例。Oracle 数据库有许多函数,其结构为 "schema.package.function()"。问题是,我无法在 H2 中为集成测试用例重新创建相同的函数,因为 H2 将其视为 "dbname.schemaname.functionname()" 的形式。

例如:当代码在 Oracle 数据库上运行时,"SELECT MDM.NEXT_KEYS.NEXT_REF_SOURCE_KEY from dual" 是可行的。但在 H2 上进行集成测试时,它会抛出 "DB MDM not found" 的错误。因此,我将数据库名称设置为 MDM,模式名称设置为 NEXT_KEYS 在 H2 设置中。这样做是可行的。但是,现在我的下一个函数 "PAYERS.KEY_TRANSLATIONS.CORE_ENHANCED_DESC_4_KEY" 失败,显示 "DB PAYERS not found"。

由于这些 Oracle 函数被多个团队使用,更改它们并不可行。

如果在 H2 中无法实现这一点,您能否为 Spring Boot 提供一个很好的备选内存数据库呢?

非常感谢您的帮助!

英文:

In my project we are using oracle database as the main application db and H2 as in memory database to run only the integration test cases. Oracle db has many functions which are of the structure "schema.package.function()". The problem is, i'm not able to recreate the same function in H2 for integration test cases as H2 treats it in the form of "dbname.schemaname.functionname()".

for example : When code runs with oracle db , "SELECT MDM.NEXT_KEYS.NEXT_REF_SOURCE_KEY from dual" works. During integration test case on H2, it throws error "DB MDM not found". So i set the db name as MDM and schema name as NEXT_KEYS in h2 setup.It worked. But my next function PAYERS.KEY_TRANSLATIONS.CORE_ENHANCED_DESC_4_KEY fails now saying "DB PAYERS not found".

Changing the oracle functions is out of the equation as they are used by multiple teams.

If this is not possible with H2 , can you suggest a good alternate in-memory db for spring boot

Appreciate your help !

答案1

得分: 0

我已经成功解决了这个问题。在这里添加解决方案链接,以便可能会有所帮助。

设置这个标志 IGNORE_CATALOGS=TRUE 解决了这个问题。当它被启用时,目录(数据库)的名称会被忽略。

spring.datasource.url = jdbc:h2:mem:testdb;MODE=Oracle;IGNORE_CATALOGS=TRUE

请参考下面的链接 https://github.com/h2database/h2database/issues/2893

英文:

I was able to fix the issue. Adding the solution link here so that it might help someone

Setting this flag IGNORE_CATALOGS=TRUE fixed the issue. When it is enabled, name of catalog (database) is ignored.

spring.datasource.url = jdbc:h2:mem:testdb;MODE=Oracle;IGNORE_CATALOGS=TRUE

Refer the below link https://github.com/h2database/h2database/issues/2893

huangapple
  • 本文由 发表于 2020年9月17日 12:57:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63931515.html
匿名

发表评论

匿名网友

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

确定