mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Merge pull request #2867 from FOCONIS/fix-flush-transaction
FIX: Flush transaction if it is modified in callback
This commit is contained in:
2 files changed
+24
No files matched your search
@@ -885,6 +885,9 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
|||||||
public final void preCommit() {
|
public final void preCommit() {
|
||||||
internalBatchFlush();
|
internalBatchFlush();
|
||||||
firePreCommit();
|
firePreCommit();
|
||||||
|
// we must flush the batch queue again, because the callback can
|
||||||
|
// modify current transaction
|
||||||
|
internalBatchFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+21
@@ -105,4 +105,25 @@ public class JdbcTransactionTest {
|
|||||||
assertThat(postCommitCallCount.get()).isEqualTo(2); // postcommit executed twice
|
assertThat(postCommitCallCount.get()).isEqualTo(2); // postcommit executed twice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlushInCallback() {
|
||||||
|
try (Transaction transaction = DB.beginTransaction()) {
|
||||||
|
transaction.setBatchMode(true);
|
||||||
|
DB.currentTransaction().register(
|
||||||
|
new TransactionCallbackAdapter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preCommit() {
|
||||||
|
EBasic basic = new EBasic("binner1");
|
||||||
|
DB.save(basic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
EBasic basic = new EBasic("bouter1");
|
||||||
|
DB.save(basic);
|
||||||
|
transaction.commit(); // transaction will fail if recursive post-commit is failing
|
||||||
|
}
|
||||||
|
assertThat(DB.find(EBasic.class).where().eq("name", "binner1").exists()).isTrue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user