Spring Boot:H2 测试数据库无法识别“serial4”

发布于 2025-01-12 17:08:45 字数 949 浏览 2 评论 0原文

我在内存中使用 h2 来测试 spring 存储库类。 但是当 h2 尝试创建表时返回:

org.h2.jdbc.JdbcSQLNonTransientException: Unknown data type: "SERIAL4";

表的ddl显示id列是serial4数据类型。

id serial4 NOT NULL

但 h2 无法识别这一点。 原始表位于 postgresql 下。

有什么类型的解决方案吗?

谢谢

更新:

我已经更新了测试环境的applications.yaml,但结果是一样的。这是更新后的 yaml 文件:

spring:
  application:
    name: test_name
  jpa:
    database-platform: org.hibernate.dialect.H2Dialect
    show-sql: true
    properties:
      generate-ddl: true
      hibernate:
        ddl-auto: create
        format_sql: true
        jdbc:
          batch_size: 500
          lob:
            non_contextual_creation: true
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:mem:mydb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_LOWER=TRUE;MODE=POSTGRESQL;INIT=CREATE SCHEMA IF NOT EXISTS test_schema\;
logging:
  level:
    root: INFO

I'm using h2 as in memory in order to test a spring repository class.
But when h2 try to create the table return:

org.h2.jdbc.JdbcSQLNonTransientException: Unknown data type: "SERIAL4";

The ddl of the table show that the id column is a serial4 datatype.

id serial4 NOT NULL

But h2 don't recognize that.
The origina table is under postgresql.

There is any type of solution?

Thanks

UPDATE:

I've updated the applications.yaml of test enviroment, but the result is the same. Here's the updated yaml file:

spring:
  application:
    name: test_name
  jpa:
    database-platform: org.hibernate.dialect.H2Dialect
    show-sql: true
    properties:
      generate-ddl: true
      hibernate:
        ddl-auto: create
        format_sql: true
        jdbc:
          batch_size: 500
          lob:
            non_contextual_creation: true
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:mem:mydb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_LOWER=TRUE;MODE=POSTGRESQL;INIT=CREATE SCHEMA IF NOT EXISTS test_schema\;
logging:
  level:
    root: INFO

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文