How do I pass properties to Enver in Grails 3?

162 Views Asked by At

I am using Hibernate Envers in my Grails app, and trying to set the org.hibernate.envers.audit_strategy property. What is the correct way to configure this?

I have tried adding the following to application.yml:

org.hibernate:
    envers:
        audit_strategy: 'org.hibernate.envers.strategy.ValidityAuditStrategy'

I tried several variations on this, and also tried setting it in application.groovy, but I cannot get Envers to read it.

I'd rather include it in the project source, and not set it on the command line.

Update:

Another config that does not work (application.yml):

hibernate:
    additionalProperties:
        org.hibernate:
            envers:
                audit_strategy: 'org.hibernate.envers.strategy.ValidityAuditStrategy'

Update 2:

I noticed in the debugger that there is a nested map in the config, as shown in the screenshot below. This prevents AuditEntitiesConfiguration from reading the property correctly, since it's just using map.get.

Why is this happening? Is there something wrong with my YAML format?

enter image description here

I tried simplifying my YAML setting for this property down to one line, but it didn't help:

org.hibernate.envers.audit_strategy: 'org.hibernate.envers.strategy.ValidityAuditStrategy'
1

There are 1 best solutions below

0
RMorrisey On

I found that I could make it work by modifying the Application class:

    static void main(String[] args) {
        System.setProperty('org.hibernate.envers.audit_strategy', 'org.hibernate.envers.strategy.ValidityAuditStrategy')
        GrailsApp.run(Application, args)
    }

I'm open to better solutions.