0

I create the following relational table with a primary key (Liquibase script below):

  <changeSet author="..." id="1661758077399">
    <createTable tableName="idp_groups">
      <column name="idp_id" type="VARCHAR(255)">
        <constraints nullable="false"/>
      </column>
      <column name="enterprise_group_id" type="UUID">
        <constraints nullable="false"/>
      </column>
    </createTable>
  </changeSet>

  <changeSet author="..." id="1661758077399-2">
    <addPrimaryKey columnNames="idp_id, enterprise_group_id" constraintName="idp_groups_pkey" tableName="idp_groups"/>
  </changeSet>

There are no foreign keys created, just a primary key. Then I try to add some test sql data like this:

 insert into idp_groups (idp_id, enterprise_group_id)
 values ('1234', '10d5584f-f2c6-4534-9224-1758de383cd7');

 insert into idp_groups (idp_id, enterprise_group_id) values ('1234',
 '20d5584f-f2c6-4534-9224-1758de383cd7');

 insert into idp_groups (idp_id, enterprise_group_id)
 values ('2345', '40d5584f-f2c6-4534-9224-1758de383cd7');

The test db is hsql (latest version):

<dependency>
  <groupId>org.hsqldb</groupId>
  <artifactId>hsqldb</artifactId>
  <version>2.7.0</version>
  <scope>test</scope>
</dependency>

The test itself:

  @Sql({
      "/data/idps.sql",
      "/data/groups.sql",
      "/data/idp_groups.sql"
  })
  @Test
  public void testSyncTask() {
    when(rbacIdpGroupsClient.getIdpGroups(any(), eq("1234"), any(), any(), any(), any(), any())).thenReturn(
        getRbacResponseIdp1());
    when(rbacIdpGroupsClient.getIdpGroups(any(), eq("2345"), any(), any(), any(), any(), any())).thenReturn(
        getRbacResponseIdp2());

    idpGroupSynchronizer.syncGroupsRbac();
  }

And I get the following error:

org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of class path resource [data/idp_groups.sql]: insert into idp_groups (idp_id, enterprise_group_id) values ('1234', '10d5584f-f2c6-4534-9224-1758de383cd7'); nested exception is java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: NOT NULL check constraint; SYS_CT_10265 table: IDP_GROUPS column: IDP_ENTITY_ID

SYS_CT tables are automatically created by hsql for constraints reasons. However it doesn't make any sense as I'm providing both columns in the insert, so there is no null value.. Am I doing something wrong or is there a problem on HSQL's end?

Rnam
  • 65
  • 1
  • 7

1 Answers1

0

So, the problem was I had enabled ddl-auto, so Hibernate was creating additional tables and columns according to my entities. After switching to ddl-auto none, the problem disappeared:

spring:
  jpa:
    hibernate:
      ddl-auto: none
Rnam
  • 65
  • 1
  • 7