3

We have a multi-tenant Spring Web app setup with Hibernate as JPA. We use a tenant per schema. We like to use tools like Envers or JaVers for Audit logging such that every db schema has its own audit tables. How have you implemented this? Or would you implement it?

I have changed the code of JaVers a bit such that when it retrieves the db schema I will return the db schema that belongs to the logged-in user. This works partly as some tables are contained in the shared public schema, however, currently at the place were JaVers retrieves the db schema I don't have this entity/table info. I am thinking about changing JaVers code further such that I have this entity/table info, but isn't there a better library/approach to support multi-tenant?

Sorry for not posting any code

edbras
  • 4,145
  • 9
  • 41
  • 78
  • Not sure if I understood correctly, but you can define, with Hibernate Envers, in the same entity the audit configuration. Using for example @AuditTable( schema = "…​" ). Reference: https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#envers. If your entities already define which schema they belongs this will be fairly easy. – pringi Oct 10 '22 at 08:44
  • 1
    Thanks @pringi, but tenants are created runtime with generated db schema names, so they can't be specified beforehand. We use Hibernate mutli tenancy mechanism with a Dbschema resolver class that hibernate uses to request for the db schema when it's not defined on the Table annotation of the entity. – edbras Oct 11 '22 at 12:15

0 Answers0