{"record":{"id":"5cd3ad44a8d668d8","repo":"apache/beam","slug":"write-statement-and-table-are-mutually-exclusive","errorCode":null,"errorMessage":"Write Statement and Table are mutually exclusive configurations","messagePattern":"Write Statement and Table are mutually exclusive configurations","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcWriteSchemaTransformProvider.java","lineNumber":416,"sourceCode":"        throw new IllegalArgumentException(\n            \"If JDBC type is not specified, then Driver Class Name and Driver Jars must be specified.\");\n      }\n      if (!driverClassNamePresent && !jdbcTypePresent) {\n        throw new IllegalArgumentException(\n            \"One of JDBC Driver class name or JDBC type must be specified.\");\n      }\n      if (jdbcTypePresent\n          && !JDBC_DRIVER_MAP.containsKey(Objects.requireNonNull(jdbcType).toLowerCase())) {\n        throw new IllegalArgumentException(\n            \"JDBC type must be one of \" + JDBC_DRIVER_MAP.keySet() + \" but was \" + jdbcType);\n      }\n\n      boolean writeStatementPresent =\n          (getWriteStatement() != null && !\"\".equals(getWriteStatement()));\n      boolean locationPresent = (getLocation() != null && !\"\".equals(getLocation()));\n\n      if (writeStatementPresent && locationPresent) {\n        throw new IllegalArgumentException(\n            \"Write Statement and Table are mutually exclusive configurations\");\n      }\n      if (!writeStatementPresent && !locationPresent) {\n        throw new IllegalArgumentException(\"Either Write Statement or Table must be set.\");\n      }\n    }\n\n    public static Builder builder() {\n      return new AutoValue_JdbcWriteSchemaTransformProvider_JdbcWriteSchemaTransformConfiguration\n          .Builder();\n    }\n\n    public abstract Builder toBuilder();\n\n    @AutoValue.Builder\n    public abstract static class Builder {\n      public abstract Builder setDriverClassName(String value);\n","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcWriteSchemaTransformProvider.java#L398-L434","documentation":"JdbcWriteSchemaTransformConfiguration supports writing either a custom write statement OR a table (given via location), but not both. Supplying both is ambiguous, so validate() throws this IllegalArgumentException.","triggerScenarios":"Setting both setWriteStatement(...) and setLocation(...) on the configuration before validate().","commonSituations":"Merging configs where a template already contains a write statement and the user also sets the target table; scripted config assembly appending both fields unconditionally.","solutions":["Remove setWriteStatement(...) and keep setLocation(table) for a plain table insert","Or remove setLocation(...) and keep the custom write statement","Decide the write mode in code: if statement != null, skip setting location"],"exampleFix":"// before\nbuilder().setJdbcUrl(url).setLocation(\"orders\").setWriteStatement(\"INSERT INTO orders VALUES(?)\").build();\n// after\nbuilder().setJdbcUrl(url).setWriteStatement(\"INSERT INTO orders VALUES(?)\").build();","handlingStrategy":"validation","validationCode":"if (cfg.getWriteStatement() != null && !cfg.getWriteStatement().isEmpty()\n    && cfg.getLocation() != null && !cfg.getLocation().isEmpty()) {\n  throw new IllegalArgumentException(\"Set either writeStatement or location, not both\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  config.validate();\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"mutually exclusive\")) {\n    LOG.error(\"Drop either writeStatement or location from the config\");\n  }\n  throw e;\n}","preventionTips":["Pick one write mode per configuration object; never merge templates blindly","When deriving config from parameters, set location only if statement is absent"],"tags":["jdbc","beam","config","conflict"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}