From 6e85abcf7a1311f628a6ece690830be51be6a9b4 Mon Sep 17 00:00:00 2001 From: Lukasz Antoniak Date: Tue, 20 Mar 2012 18:43:14 +0100 Subject: [PATCH] HHH-7017 - Fix and test --- .../envers/synchronization/AuditProcess.java | 9 +++++---- .../test/integration/flush/ManualFlush.java | 8 ++++---- .../flush/ManualFlushAutoCommitDisabled.java | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/flush/ManualFlushAutoCommitDisabled.java diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java index 54a87e36f0..b74c39feae 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/synchronization/AuditProcess.java @@ -28,6 +28,7 @@ import java.util.LinkedList; import java.util.Map; import java.util.Queue; +import org.hibernate.ConnectionReleaseMode; import org.hibernate.FlushMode; import org.hibernate.Session; import org.hibernate.action.spi.BeforeTransactionCompletionProcess; @@ -140,10 +141,10 @@ public class AuditProcess implements BeforeTransactionCompletionProcess { if (FlushMode.isManualFlushMode(session.getFlushMode())) { Session temporarySession = null; try { - temporarySession = session.getFactory().openTemporarySession(); - + temporarySession = ((Session) session).sessionWithOptions().transactionContext().autoClose(false) + .connectionReleaseMode(ConnectionReleaseMode.AFTER_TRANSACTION) + .openSession(); executeInSession(temporarySession); - temporarySession.flush(); } finally { if (temporarySession != null) { @@ -153,7 +154,7 @@ public class AuditProcess implements BeforeTransactionCompletionProcess { } else { executeInSession((Session) session); - // Explicity flushing the session, as the auto-flush may have already happened. + // Explicitly flushing the session, as the auto-flush may have already happened. session.flush(); } } diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/flush/ManualFlush.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/flush/ManualFlush.java index 6c642429fc..45f2d6ba8d 100644 --- a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/flush/ManualFlush.java +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/flush/ManualFlush.java @@ -86,7 +86,7 @@ public class ManualFlush extends AbstractFlushTest { @Test public void testRevisionsCounts() { - assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id)); + assertEquals(Arrays.asList(1, 2), getAuditReader().getRevisions(StrTestEntity.class, id)); } @Test @@ -94,13 +94,13 @@ public class ManualFlush extends AbstractFlushTest { StrTestEntity ver1 = new StrTestEntity("x", id); StrTestEntity ver2 = new StrTestEntity("z", id); - assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1); - assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2); + assertEquals(ver1, getAuditReader().find(StrTestEntity.class, id, 1)); + assertEquals(ver2, getAuditReader().find(StrTestEntity.class, id, 2)); } @Test public void testCurrent() { - assert getEntityManager().find(StrTestEntity.class, id).equals(new StrTestEntity("z", id)); + assertEquals(new StrTestEntity("z", id), getEntityManager().find(StrTestEntity.class, id)); } @Test diff --git a/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/flush/ManualFlushAutoCommitDisabled.java b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/flush/ManualFlushAutoCommitDisabled.java new file mode 100644 index 0000000000..579bcf015d --- /dev/null +++ b/hibernate-envers/src/matrix/java/org/hibernate/envers/test/integration/flush/ManualFlushAutoCommitDisabled.java @@ -0,0 +1,16 @@ +package org.hibernate.envers.test.integration.flush; + +import org.hibernate.ejb.Ejb3Configuration; +import org.hibernate.testing.TestForIssue; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +@TestForIssue(jiraKey = "HHH-7017") +public class ManualFlushAutoCommitDisabled extends ManualFlush { + @Override + public void configure(Ejb3Configuration cfg) { + super.configure(cfg); + cfg.setProperty("hibernate.connection.autocommit", "false"); + } +}