liquibase-hibernate icon indicating copy to clipboard operation
liquibase-hibernate copied to clipboard

liquibase ignores envers tables postfix therefore tables missing

Open zapphyre opened this issue 7 years ago • 5 comments

I am using liquibase 3.5.3 with hibernate 5.2.9.Final and envers 5.2.12.Final.

liquibase configuration: pom.xml:

            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.5.3</version>
                <configuration>
                    <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                    <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                    <referenceUrl>
                        hibernate:spring:com.nws.vedica.model?dialect=org.hibernate.dialect.PostgreSQL92Dialect
                    </referenceUrl>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate5</artifactId>
                        <version>3.6</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-beans</artifactId>
                        <version>${spring.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.data</groupId>
                        <artifactId>spring-data-jpa</artifactId>
                        <version>1.11.1.RELEASE</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.validation</groupId>
                        <artifactId>validation-api</artifactId>
                        <version>2.0.0.Final</version>
                    </dependency>
                </dependencies>
            </plugin>

liquibase.properties:

url=jdbc:postgresql://212.89.239.181:5432/vedica_db
username=vedic
password=veda
driver=org.postgresql.Driver
outputChangeLogFile=src/main/resources/liquibase-outputChangeLog.xml
changeLogFile=src/main/resources/liquibase-changeLog.xml

JPAConfig.java:

@PostConstruct
    public void init() {
        properties = new HashMap<>();
        properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
        properties.put("javax.persistence.jdbc.url", dbConnectionURL);
        properties.put("javax.persistence.jdbc.user", dbUser);
        properties.put("javax.persistence.jdbc.password", dbPassword);
        properties.put("hibernate.show_sql", log);
        properties.put("javax.persistence.jdbc.driver", "org.postgresql.Driver");
        properties.put("javax.persistence.target-database", "PostgreSQL");
        properties.put("org.hibernate.envers.audit_table_suffix", "_vers");
        properties.put("org.hibernate.envers.default_schema", "audit");
        properties.put("hibernate.integration.envers.enabled", "true");
        properties.put("hibernate.enable_lazy_load_no_trans", "true");
        properties.put("hibernate.jdbc.batch_size", "20");
        properties.put("hibernate.jdbc.batch_versioned_data", "true");
//        properties.put("hibernate.order_inserts", "true");
//        properties.put("hibernate.order_updates", "true");

        properties.put("hibernate.c3p0.timeout", "300");
        properties.put("hibernate.c3p0.min_size", "7");
        properties.put("hibernate.c3p0.max_size", "20");
        properties.put("hibernate.c3p0.max_statements", "50");
        properties.put("hibernate.c3p0.hibernate.c3p0.idle_test_period", "3000");
        properties.put("hibernate.c3p0.preferredTestQuery","SELECT 1");
        properties.put("hibernate.c3p0.testConnectionOnCheckout","true");
        properties.put("hibernate.c3p0.acquireRetryAttempts","1");
        properties.put("hibernate.c3p0.acquireIncrement","1");
        properties.put("hibernate.c3p0.idleConnectionTestPeriod","60");
        properties.put("hibernate.jdbc.lob.non_contextual_creation","true");
    }

so you see, my audit tables gets generated in 'audit' catalog with the '_vers' suffix.

when I run 'mvn liquibase:diff' it keeps telling me that audit tables are missing:

Missing Table(s): 
     DocShreddingInfo_AUD
     DocType_keywords_AUD
     DocVersion_AUD
     MetaFieldValidityRules_AUD
     Metadata_additions_AUD
     Metadata_json_AUD
     Metadata_patterns_AUD
     PartyKind_AUD
     ValidityRule_AUD
     document_AUD
     document_type_AUD
     product_instance_AUD
     related_doc_AUD
     shredding_type_AUD
     task_AUD

so it can't read suffinx information form the hibernate configuration. I have tried set @AuditTable on the entity with the value of the actual table name, but does not help.

advice, please.

┆Issue is synchronized with this Jira Bug by Unito

zapphyre avatar Oct 27 '17 11:10 zapphyre

these might be helpful: #137 #99

crtk avatar Oct 28 '17 01:10 crtk

I have seen and tried those, that's why I mention I tried @Audittable. But that's workaround anyway. Hope someone can solve it finally.

zapphyre avatar Oct 31 '17 09:10 zapphyre

I wrote another workaournd in #99 which could solve this problem. Just set the "unsupported" properties via the environment (i.e -Dorg.hibernate.envers.audit_table_suffix=_vers)

MalteKrueger avatar Jun 14 '18 22:06 MalteKrueger

Yes, now the problem is that it makes diff of the 'audit' postgre schema but on update goal it updates 'public' schema with the audit tables.. Is there an option to make liquibase preserve schema information?

zapphyre avatar Jul 03 '18 08:07 zapphyre

Does someone has a fix for this? Struggling with this problem too. @MalteKrueger's workaround seems not to work out for me.

felixoi avatar May 05 '23 13:05 felixoi