如何使用 database-rider 在 table 中插入数据集并将列定义为 GENERATED ALWAYS?

How to insert DataSet in table with column defined as GENERATED ALWAYS using database-rider?

正在尝试使用 DBRider @DataSet 注释插入 test_data.xml。

XML 包含如下数据:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dataset SYSTEM "src\main\resources\test_dataset.dtd">
<dataset>
    <groups group_name='SG-83'/>
</dataset>

我的架构如下:

CREATE TABLE groups
(
    group_id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    group_name character varying(256) COLLATE pg_catalog."default" NOT NULL
)

测试失败,跟踪如下:

Caused by: com.github.database.rider.core.exception.DataBaseSeedingException: Could not initialize dataset: test_data.xml
    at com.github.database.rider.core.dataset.DataSetExecutorImpl.createDataSet(DataSetExecutorImpl.java:141)
    at com.github.database.rider.core.RiderRunner.runBeforeTest(RiderRunner.java:44)
    ... 50 more
Caused by: org.dbunit.DatabaseUnitException: Exception processing table name='groups'
    at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:240)
    at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79)
    at com.github.database.rider.core.dataset.DataSetExecutorImpl.createDataSet(DataSetExecutorImpl.java:132)
    ... 51 more
Caused by: org.postgresql.util.PSQLException: ERROR: cannot insert into column "group_id"
  Detail: Column "group_id" is an identity column defined as GENERATED ALWAYS.
  Hint: Use OVERRIDING SYSTEM VALUE to override.

有没有办法不覆盖 group_id 列并使用 postgres 自动生成的值?

自己发现问题:

在我的“test_dataset.dtd”中,我描述了 group_id 列,因此 dbunit 试图插入 NULL “test_data.xml”中没有明确值时的值。因此,如果我从 .dtd 文件中删除 group_id 定义,测试数据将以 group_id 自动生成的值进入 postgres .