Spring Boot H2 DB模式Oracle [英] Spring boot H2 db mode oracle

查看:204
本文介绍了Spring Boot H2 DB模式Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Boot应用程序(2.3.1.RELEASE,ojdbc8),基本上它已连接到oracle数据库.

Hi I have a spring boot app (2.3.1.RELEASE, ojdbc8) and basically it is connected to an oracle database.

spring boot应用程序在连接到oracle db时开始查找,但是在以下情况下无法启动集成测试已连接到H2嵌入式数据库,并且我的某些查询失败并显示以下错误消息:

The spring boot app starts find when it is connected to the oracle db.However fails to start when the integration test is connected to a H2 embedded db and some of my queries are failing with the following error message:

Caused by: java.lang.NullPointerException: null
    at org.hibernate.hql.internal.NameGenerator.generateColumnNames(NameGenerator.java:27)
    at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.generateColumnNames(SessionFactoryHelper.java:434)

我设法通过在我的application-test.yml文件中添加以下代码行来使其工作:

I manage to make it work by adding adding the following line of code in my application-test.yml file:

spring:
  jpa:
    database-platform: org.hibernate.dialect.Oracle10gDialect

请在application-test.yml配置以下进行罚款:

Please fine below application-test.yml config:

spring.datasource:
  url: jdbc:h2:mem:db;Mode=Oracle;DB_CLOSE_DELAY=-1
  username: sa
  password: sa
  driverClassName: org.h2.Driver
# added empty context path to override application.yml context path
server:
  servlet:
    contextPath:
spring:
  jpa:
    database-platform: org.hibernate.dialect.Oracle10gDialect

应用程序启动良好且集成成功完成,但是以下异常可以显示在日志中:

The application starts well and integration completed successfully however the following exception can be shown in the log:

org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "ALL_SEQUENCES" not found; SQL statement:
select * from all_sequences [42102-200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:453) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:429) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:205) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:181) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.readTableOrView(Parser.java:7628) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.readTableFilter(Parser.java:1970) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parseSelectFromPart(Parser.java:2827) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parseSelect(Parser.java:2959) ~[h2-1.4.200.jar:1.4.200]
    
    
    ....
    
    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "drop table dash_processed cascade constraints" via JDBC Statement
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:241) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:145) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) ~[hibernate-core-5.4.17.Final.jar:5.4.17.Final]
    
    ...
    
    drop table dash_processed cascade constraints [42102-200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:453) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:429) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:205) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:181) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.ddl.DropTable.prepareDrop(DropTable.java:65) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.ddl.DropTable.update(DropTable.java:124) ~[h2-1.4.200.jar:1.4.200]

有什么主意我该如何阻止这些错误?

Any idea how i can stop those errors?

预先感谢

推荐答案

要使用h2数据库模拟Oracle和序列对象,请将此行添加到spring boot application.properties:

To simulate the Oracle and sequence objects with h2 database add this line to your spring boot application.properties:

spring.datasource.url=jdbc:h2:mem:testdb;Mode=Oracle

h2文档 Oracle兼容模式部分

这篇关于Spring Boot H2 DB模式Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆