0

I am migrating from real postgres testing to testContainers using spring-boot. The test fails with this exception:

Reason: liquibase.exception.DatabaseException: ERROR: update or delete on table "table1" violates foreign key constraint "fk30d6gcohuxxjs6f3cqwtbtu69" on table "table2"
Détail : Key (id)=(2152) is still referenced from table "table2". [Failed SQL: (0) DELETE FROM table1]
// application.yml
...
spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    hikari:
      auto-commit: false
      poolName: Hikari
      maximum-pool-size: 1
  jpa:
    database-platform: tech.jhipster.domain.util.FixedPostgreSQL10Dialect
    open-in-view: false
    hibernate:
      ddl-auto: none
      naming:
        physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
        implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
    properties:
      hibernate.id.new_generator_mappings: true
      hibernate.connection.provider_disables_autocommit: true
      hibernate.cache.use_second_level_cache: false
      hibernate.cache.use_query_cache: false
      hibernate.generate_statistics: false
      hibernate.hbm2ddl.auto: validate
      hibernate.jdbc.time_zone: UTC
      hibernate.query.fail_on_pagination_over_collection_fetch: true
// changeset file (liquibase)
<addForeignKeyConstraint constraintName="fk_name"
                                 baseTableName="table2"
                                 baseColumnNames="table2_id"
                                 referencedTableName="table1"
                                 referencedColumnNames="id"
                                 onDelete="CASCADE"/>

Is there any configuration for testContainers in order to accept cascade delete ?

Spring-boot version: 2.7.3

liquibase version: 3.7.0

testContainers version: 1.17.3

Jhipster version: 7.9.3

3
  • 1
    Have you read stackoverflow.com/questions/8435251/… ? I think you should log SQL statements generated by Hibernate, it might not be what you expect because some annotations are missing Oct 7 at 21:39
  • You mean activating hibernate log statements solve the problem ? That's what I did and it works. When I removed hibernate logs, it still works. Strange Oct 8 at 10:55
  • No I did not mean that, quite strange :D I was suggesting using something like datasource-proxy to really see the SQL that gets executed by database and validate your hypothesis. Oct 8 at 12:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.