0 Replies Latest reply on Dec 12, 2018 4:38 AM by Raul Mordillo

    Audit tables in different schemas with one revinfo per schema with one db connection on SpringBoot

    Raul Mordillo Newbie

      Good day ,

       

      I want to audit tables that are in different schemas, so I created one revinfo per schema and one _aud table per table to be audited.
      Then I'm using the following annotation to tell envers where to find _aud tables.

       

      @AuditTable(value = "condition_rate_aud",schema = "backoffice")

       

      As you can see, whenever I persist data the following happens:

       

      It persist revision info

      DEBUG SQL - insert into revinfo (rev, revtstmp) values (null, ?)

       

      And then it tries to persist condition_rate_aud date:

       

      insert into backoffice.condition_rate_aud (revtype, charge_first_night, code, color, early_charge, minimum_charge, name, ordering, property_ticker, ticker, type, modification_policy_id, id, rev) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23506-197]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause

      org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "fk_condition_rate_aud__revinfo: ""backoffice"".""condition_rate_aud"" FOREIGN KEY(""rev"") REFERENCES ""backoffice"".""revinfo""(""rev"") (1)"; SQL statement:

      insert into backoffice.condition_rate_aud (revtype, charge_first_night, code, color, early_charge, minimum_charge, name, ordering, property_ticker, ticker, type, modification_policy_id, id, rev) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23506-197]

       

      Obviously it throws an error because Envers persisted revision data into the revinfo table of the main db connection schema, not into backoffice.revinfo table.

       

      is there a way to tell Envers to use the condition_rate_aud schema when persisting to revinfo?

       

      thanks