Repository: jdbi/jdbi
Issue: Unable generate keys for a not prepared batch if inserted list size to contain BatchChunkSize

    @SqlBatch("INSERT INTO users (name) VALUES (:name)")
    @GetGeneratedKeys
    public abstract int[] insertBatch(@BindBean List<User> users, @BatchChunkSize int chunk);

finished with `java.lang.IllegalArgumentException: Unable generate keys for a not prepared batch` if 
last parts.size()==0 (inserted list size to contain BatchChunkSize)
```
java.lang.IllegalArgumentException: Unable generate keys for a not prepared batch

	at org.skife.jdbi.v2.PreparedBatch.internalBatchExecute(PreparedBatch.java:147)
	at org.skife.jdbi.v2.PreparedBatch.executeAndGenerateKeys(PreparedBatch.java:105)
	at org.skife.jdbi.v2.PreparedBatch.executeAndGenerateKeys(PreparedBatch.java:134)
	at org.skife.jdbi.v2.sqlobject.BatchHandler$2.value(BatchHandler.java:75)
	at org.skife.jdbi.v2.sqlobject.BatchHandler$5.inTransaction(BatchHandler.java:231)
	at org.skife.jdbi.v2.sqlobject.BatchHandler$5.inTransaction(BatchHandler.java:227)
	at org.skife.jdbi.v2.tweak.transactions.LocalTransactionHandler.inTransaction(LocalTransactionHandler.java:183)
	at org.skife.jdbi.v2.BasicHandle.inTransaction(BasicHandle.java:338)
	at org.skife.jdbi.v2.sqlobject.BatchHandler.executeBatch(BatchHandler.java:226)
	at org.skife.jdbi.v2.sqlobject.BatchHandler.invoke(BatchHandler.java:204)
	at org.skife.jdbi.v2.sqlobject.SqlObject.invoke(SqlObject.java:224)
	at org.skife.jdbi.v2.sqlobject.SqlObject$3.intercept(SqlObject.java:133)
	at 
```
what for `PreparedBatch` line 146-148 ?

Changed files:
src/test/java/org/skife/jdbi/v2/sqlobject/TestBatching.java, src/main/java/org/skife/jdbi/v2/sqlobject/BatchHandler.java

diff --git a/src/main/java/org/skife/jdbi/v2/sqlobject/BatchHandler.java b/src/main/java/org/skife/jdbi/v2/sqlobject/BatchHandler.java
index b4210b644..a8c19c8a8 100644
--- a/src/main/java/org/skife/jdbi/v2/sqlobject/BatchHandler.java
+++ b/src/main/java/org/skife/jdbi/v2/sqlobject/BatchHandler.java
@@ -201,7 +201,9 @@ class BatchHandler extends CustomizingStatementHandler
         }
 
         //execute the rest
-        rs_parts.add(executeBatch(handle, batch));
+        if (batch.getSize() > 0) {
+            rs_parts.add(executeBatch(handle, batch));
+        }
 
         // combine results
         int end_size = 0;
diff --git a/src/test/java/org/skife/jdbi/v2/sqlobject/TestBatching.java b/src/test/java/org/skife/jdbi/v2/sqlobject/TestBatching.java
index 876414065..e04a905d2 100644
--- a/src/test/java/org/skife/jdbi/v2/sqlobject/TestBatching.java
+++ b/src/test/java/org/skife/jdbi/v2/sqlobject/TestBatching.java
@@ -13,6 +13,7 @@
  */
 package org.skife.jdbi.v2.sqlobject;
 
+import java.util.Collections;
 import org.h2.jdbcx.JdbcDataSource;
 import org.junit.After;
 import org.junit.Before;
@@ -30,6 +31,7 @@ import java.util.List;
 import java.util.UUID;
 
 import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
 
 public class TestBatching
@@ -166,6 +168,13 @@ public class TestBatching
         b.invalidInsertString("bob");
     }
 
+    @Test
+    public void testEmptyBatchWithGeneratedKeys() {
+        UsesBatching b = handle.attach(UsesBatching.class);
+        int[] updateCounts = b.insertChunkedGetKeys();
+        assertEquals(0, updateCounts.length);
+    }
+
     @BatchChunkSize(4)
     @UseStringTemplate3StatementLocator
     public static interface UsesBatching
@@ -189,6 +198,10 @@ public class TestBatching
         @SqlBatch
         public int[] insertChunked(@BatchChunkSize int size, @BindBean("it") Iterable<Something> its);
 
+        @SqlBatch("insert into something (id, name) values (:id, :name)")
+        @GetGeneratedKeys(columnName = "id")
+        public int[] insertChunkedGetKeys(Something... values);
+
         @SqlQuery("select count(*) from something")
         public int size();