diff --git a/src/main/java/com/avaje/ebean/TxScope.java b/src/main/java/com/avaje/ebean/TxScope.java
index af1b56881..0811f63b5 100644
--- a/src/main/java/com/avaje/ebean/TxScope.java
+++ b/src/main/java/com/avaje/ebean/TxScope.java
@@ -16,7 +16,7 @@ import java.util.ArrayList;
* This object is used internally with the enhancement of a method with
* Transactional annotation.
*
- *
+ *
* @see TxCallable
* @see TxRunnable
* @see Ebean#execute(TxScope, TxCallable)
@@ -44,27 +44,6 @@ public final class TxScope {
ArrayList> noRollbackFor;
- /**
- * Return true if PersistBatch has been set.
- */
- public boolean isBatchSet() {
- return batch != null && batch != PersistBatch.INHERIT;
- }
-
- /**
- * Return true if batch on cascade has been set.
- */
- public boolean isBatchOnCascadeSet() {
- return batchOnCascade != null && batchOnCascade != PersistBatch.INHERIT;
- }
-
- /**
- * Return true if batch size has been set.
- */
- public boolean isBatchSizeSet() {
- return batchSize > 0;
- }
-
/**
* Helper method to create a TxScope with REQUIRES.
*/
@@ -130,6 +109,44 @@ public final class TxScope {
+ "] rollbackFor[" + rollbackFor + "] noRollbackFor[" + noRollbackFor + "]";
}
+ /**
+ * Return true if PersistBatch has been set.
+ */
+ public boolean isBatchSet() {
+ return batch != null && batch != PersistBatch.INHERIT;
+ }
+
+ /**
+ * Return true if batch on cascade has been set.
+ */
+ public boolean isBatchOnCascadeSet() {
+ return batchOnCascade != null && batchOnCascade != PersistBatch.INHERIT;
+ }
+
+ /**
+ * Return true if batch size has been set.
+ */
+ public boolean isBatchSizeSet() {
+ return batchSize > 0;
+ }
+
+ /**
+ * Check for batchSize being set without batch mode and use this to imply PersistBatch.ALL.
+ */
+ public void checkBatchMode() {
+ if (batchSize > 0 && notSet(batch) && notSet(batchOnCascade)) {
+ // Use setting the batchSize as implying PersistBatch.ALL for @Transactional
+ batch = PersistBatch.ALL;
+ }
+ }
+
+ /**
+ * Return true if the mode is considered not set.
+ */
+ private boolean notSet(PersistBatch batchMode) {
+ return batchMode == null || batchMode == PersistBatch.INHERIT;
+ }
+
/**
* Return the transaction type.
*/
diff --git a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultServer.java b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultServer.java
index dad4acb29..8a1934a23 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultServer.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultServer.java
@@ -683,6 +683,9 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
if (txScope == null) {
// create a TxScope with default settings
txScope = new TxScope();
+ } else {
+ // check for implied batch mode via setting batchSize
+ txScope.checkBatchMode();
}
SpiTransaction suspended = null;
diff --git a/src/test/java/com/avaje/ebean/TxScopeTest.java b/src/test/java/com/avaje/ebean/TxScopeTest.java
new file mode 100644
index 000000000..5c3a4245b
--- /dev/null
+++ b/src/test/java/com/avaje/ebean/TxScopeTest.java
@@ -0,0 +1,67 @@
+package com.avaje.ebean;
+
+import com.avaje.ebean.config.PersistBatch;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TxScopeTest {
+
+ @Test
+ public void checkBatchMode_when_bothNull() throws Exception {
+
+ TxScope scope = new TxScope();
+ scope.setBatchSize(100);
+
+ assertNull(scope.getBatch());
+ assertNull(scope.getBatchOnCascade());
+
+ scope.checkBatchMode();
+ assertEquals(scope.getBatch(), PersistBatch.ALL);
+ }
+
+ @Test
+ public void checkBatchMode_when_bothInherit() throws Exception {
+
+ TxScope scope = new TxScope();
+ scope.setBatchSize(100);
+ scope.setBatch(PersistBatch.INHERIT);
+ scope.setBatchOnCascade(PersistBatch.INHERIT);
+
+ scope.checkBatchMode();
+ assertEquals(scope.getBatch(), PersistBatch.ALL);
+ }
+
+ @Test
+ public void checkBatchMode_when_batchSizeZero_and_onCascadeInherit() throws Exception {
+
+ TxScope scope = new TxScope();
+ scope.setBatchOnCascade(PersistBatch.INHERIT);
+
+ scope.checkBatchMode();
+ assertNull(scope.getBatch());
+ }
+
+ @Test
+ public void checkBatchMode_when_batchSizeZero_and_bothInherit() throws Exception {
+
+ TxScope scope = new TxScope();
+ scope.setBatch(PersistBatch.INHERIT);
+ scope.setBatchOnCascade(PersistBatch.INHERIT);
+
+ scope.checkBatchMode();
+ assertEquals(scope.getBatch(), PersistBatch.INHERIT);
+ }
+
+ @Test
+ public void checkBatchMode_when_onCascadeSet() throws Exception {
+
+ TxScope scope = new TxScope();
+ scope.setBatchSize(100);
+ scope.setBatchOnCascade(PersistBatch.INSERT);
+
+ scope.checkBatchMode();
+ assertNull(scope.getBatch());
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/avaje/tests/batchinsert/TestBatchInsertSimple.java b/src/test/java/com/avaje/tests/batchinsert/TestBatchInsertSimple.java
index 55157fb47..20aec87a8 100644
--- a/src/test/java/com/avaje/tests/batchinsert/TestBatchInsertSimple.java
+++ b/src/test/java/com/avaje/tests/batchinsert/TestBatchInsertSimple.java
@@ -53,7 +53,7 @@ public class TestBatchInsertSimple extends BaseTestCase {
saveWithFullBatchMode();
}
- @Transactional(batch=PersistBatch.ALL, batchSize=50)
+ @Transactional(batchSize=50)
public void saveWithFullBatchMode() {
int numOfMasters = 4;