diff --git a/java/jdbc/src/main/java/io/vitess/jdbc/VitessStatement.java b/java/jdbc/src/main/java/io/vitess/jdbc/VitessStatement.java
index <HASH>..<HASH> 100644
--- a/java/jdbc/src/main/java/io/vitess/jdbc/VitessStatement.java
+++ b/java/jdbc/src/main/java/io/vitess/jdbc/VitessStatement.java
@@ -618,7 +618,7 @@ public class VitessStatement implements Statement {
                     }
                     updateCounts[i] = truncatedUpdateCount;
                     long insertId = cursorWithError.getCursor().getInsertId();
-                    if (this.retrieveGeneratedKeys && !queryBatchUpsert || insertId > 0) {
+                    if (this.retrieveGeneratedKeys && (!queryBatchUpsert || insertId > 0)) {
                         generatedKeys.add(new long[]{insertId, truncatedUpdateCount});
                     }
                 } catch (SQLException ex) {
Paren around boolean statement for clarity