Allow specifying the foreign-key names on audit tables

Description

During the application startup, I've got this error (Liquibase have created AUD tables yet):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 2019-10-02 19:18:51.630 DEBUG [-,,,] 59088 --- [ main] o.h.e.c.i.m.AuditMetadataGenerator : Generating first-pass auditing mapping for entity hu.test.core.dbo.Address (...) 2019-10-02 19:18:51.751 DEBUG [-,,,] 59088 --- [ main] o.h.e.c.i.m.AuditMetadataGenerator : Generating second-pass auditing mapping for entity hu.test.core.dbo.Address Hibernate: alter table address_aud add constraint FKcc7vlgg86eqe1dmvivbkv046v foreign key (rev) references revinfo 2019-10-02 19:18:53.540 WARN [-,,,] 59088 --- [ main] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL "alter table address_aud add constraint FKcc7vlgg86eqe1dmvivbkv046v foreign key (rev) references revinfo" via JDBC Statement org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table address_aud add constraint FKcc7vlgg86eqe1dmvivbkv046v foreign key (rev) references revinfo" via JDBC Statement at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applyForeignKeys(AbstractSchemaMigrator.java:433) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:249) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:184) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:320) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1821) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE] at hu.test.core.Application.main(Application.java:12) ~[classes/:na] Caused by: java.sql.SQLSyntaxErrorException: ORA-02275: such a referential constraint already exists in the table at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:509) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:461) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1104) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:550) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:268) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:655) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:229) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:41) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:928) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1205) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1823) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1778) ~[jdbc-10.jar:19.3.0.0.0] at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:303) ~[jdbc-10.jar:19.3.0.0.0] at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.2.0.jar:na] at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.4.6.Final.jar:5.4.6.Final] ... 33 common frames omitted Caused by: oracle.jdbc.OracleDatabaseException: ORA-02275: such a referential constraint already exists in the table at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:513) ~[jdbc-10.jar:19.3.0.0.0] ... 48 common frames omitted

As I see, the root cause is the Liquibase part. I've created the foreign key yet, but Envers doesn't check that.

application.yml:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 spring: datasource: url: ${DATASOURCE_URL} username: ${DATASOURCE_USERNAME} password: ${DATASOURCE_PASSWORD} driver-class-name: "oracle.jdbc.OracleDriver" initialization-mode: never jpa: hibernate: ddl-auto: update naming: implicit-strategy: "org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy" physical-strategy: "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy" database-platform: "org.hibernate.dialect.Oracle12cDialect" show-sql: true

 

Environment

Oracle 18.0.0
Spring Boot 2.1.3.RELEASE
Oracle JVM
Windows 10
Liquibase

Status

Assignee

Chris Cranford

Reporter

Attila Hajdu

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major
Configure