diff --git a/src/main/java/io/ebean/Ebean.java b/src/main/java/io/ebean/Ebean.java
index 48132a90c..5fbd9aa83 100644
--- a/src/main/java/io/ebean/Ebean.java
+++ b/src/main/java/io/ebean/Ebean.java
@@ -428,6 +428,24 @@ public final class Ebean {
return serverMgr.getDefaultServer().currentTransaction();
}
+ /**
+ * The batch will be flushing automatically but you can use this to explicitly
+ * flush the batch if you like.
+ *
+ * Flushing occurs automatically when:
+ *
+ *
+ * - the batch size is reached
+ * - A query is executed on the same transaction
+ * - UpdateSql or CallableSql are mixed with bean save and delete
+ * - Transaction commit occurs
+ * - A getter method is called on a batched bean
+ *
+ */
+ public static void flush() {
+ currentTransaction().flush();
+ }
+
/**
* Register a TransactionCallback on the currently active transaction.
*
diff --git a/src/main/java/io/ebean/Transaction.java b/src/main/java/io/ebean/Transaction.java
index 6b645f9b6..2a6169c65 100644
--- a/src/main/java/io/ebean/Transaction.java
+++ b/src/main/java/io/ebean/Transaction.java
@@ -427,6 +427,7 @@ public interface Transaction extends AutoCloseable {
* A query is executed on the same transaction
* UpdateSql or CallableSql are mixed with bean save and delete
* Transaction commit occurs
+ * A getter method is called on a batched bean
*
*/
void flush() throws PersistenceException;
diff --git a/src/test/java/org/tests/transaction/TestBatchModelFlush.java b/src/test/java/org/tests/transaction/TestBatchModelFlush.java
index 752ad8096..16a8cd684 100644
--- a/src/test/java/org/tests/transaction/TestBatchModelFlush.java
+++ b/src/test/java/org/tests/transaction/TestBatchModelFlush.java
@@ -1,6 +1,7 @@
package org.tests.transaction;
import io.ebean.BaseTestCase;
+import io.ebean.Ebean;
import io.ebean.annotation.Transactional;
import org.junit.Test;
import org.tests.model.m2m.MnyB;
@@ -23,5 +24,9 @@ public class TestBatchModelFlush extends BaseTestCase {
bean2.db().flush();
new MnyB("TestBatchModelFlush_4").save();
+ Ebean.flush();
+
+ // the rest is flushed on commit
+ new MnyB("TestBatchModelFlush_5").save();
}
}