Out of Date
Details
Details
Assignee
Unassigned
UnassignedReporter
Former user
Former user(Deactivated)Labels
Components
Affects versions
Priority
Created October 24, 2017 at 8:35 AM
Updated April 8, 2022 at 1:06 PM
Resolved April 8, 2022 at 1:06 PM
So I spent about a week investigating this bug and I am finally completely lost, so I hope someone more competent will know what to do about this. Here is the scenario:
I am running Arquillian test which starts Wildfly and deploys an application which uses Infinispan configured to persist data using Hibernate/JPA. The "hibernate.hbm2ddl.auto" is set to "update", so between each test Hibernate will try to update DB schema. The first pass, on an empty database will go without problems, however the second pass will crash.
The issue seems to be that one of the persisted objects contains a Set<String> variable for which Hibernate creates a separate table, and the joins it to the main object table. It will attempt to generate a name for the Foreign key, which is an 30-character MD5 hash from concatenation of table a column names, however for some reason the hash comes out different each time, therefore failing the check on whether the FK exists and Hibernate attempts to create a new FK on the same columns, which Oracle does not allow.
The issue seems to be contained only to Oracle DBs (11g and 12c AFAIK), it does not manifest itself on other BDs we are testing (versions of MsSQL, MySQL, Postgre, DB2 etc.).
Stack trace (cut down, whole is attached):
[java] Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [alter table Person_nickNames add constraint FKsixi37kg6a1032wemki7qf6f3 foreign key (Person_id) references Person]
[java] at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:59)
[java] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:431)
[java] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:420)
[java] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applyForeignKeys(SchemaMigratorImpl.java:386)
[java] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:214)
[java] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60)
[java] at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134)
[java] at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101)
[java] at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:472)
[java] at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
[java] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
[java] at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
[java] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
...
[java] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
[java] Caused by: java.sql.SQLSyntaxErrorException: ORA-02275: such a referential constraint already exists in the table
[java] at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
[java] at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
Sadly I am not able to provide reproducer for this issue