We're updating the issue view to help you get more done. 

FK violation in ValidityAuditStrategy when when flush mode is COMMIT

Description

After changing flush mode from auto to commit, I now get a foreign key constraint violation when an existing entity was modified.
It looks like ValidityAuditStrategy.perform() is not flushing the session when flush mode is set to commit. Therefore the revision entity is not present in the database when ValidityAuditStrategy tries to update REVEND.

1 2 com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException Cannot add or update a child row: a foreign key constraint fails (`pim`.`pim_feature_groups_AUD`, CONSTRAINT `FK_d82a6ca0ceda4dd5a2f2f49a41a` FOREIGN KEY (`REVEND`) REFERENCES `custom_revisions` (`id`))
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 java.lang.reflect.Constructor.newInstance(Constructor.java:532) com.mysql.jdbc.Util.handleNewInstance(Util.java:411) com.mysql.jdbc.Util.getInstance(Util.java:386) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052) com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503) com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664) com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815) com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359) org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133) org.hibernate.envers.strategy.ValidityAuditStrategy$1.execute(ValidityAuditStrategy.java:200) org.hibernate.envers.strategy.ValidityAuditStrategy$1.execute(ValidityAuditStrategy.java:162) org.hibernate.jdbc.WorkExecutor.executeReturningWork(WorkExecutor.java:72) org.hibernate.internal.SessionImpl$3.accept(SessionImpl.java:1993) org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:284) org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:2000) org.hibernate.internal.SessionImpl.doReturningWork(SessionImpl.java:1996) org.hibernate.envers.strategy.ValidityAuditStrategy.perform(ValidityAuditStrategy.java:161) org.hibernate.envers.synchronization.work.AbstractAuditWorkUnit.perform(AbstractAuditWorkUnit.java:76) org.hibernate.envers.synchronization.AuditProcess.executeInSession(AuditProcess.java:116) org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:155) org.hibernate.envers.synchronization.AuditProcessManager$1.doBeforeTransactionCompletion(AuditProcessManager.java:62) org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:666) org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:309) org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:613) org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:105) org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)

Environment

None

Status

Assignee

Lukasz Antoniak

Reporter

Felix Scheffer

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.2.1

Priority

Major