HHH-7017 - Fix and test

This commit is contained in:
Lukasz Antoniak 2012-03-20 18:43:14 +01:00
parent 1877315ee3
commit 6e85abcf7a
3 changed files with 25 additions and 8 deletions

View File

@ -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();
}
}

View File

@ -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

View File

@ -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");
}
}