title: BulkUpdate in CouchDB using Java with Ektorp
body: <p>I have a class which derives from org.ektorp.support.CouchDbDocument:</p>
  
  <pre><code>@TypeDiscriminator( value="doc.type == 'TYPE_PRODUCT' )
  public class Product extends CouchDbDocument { 
  ....
  </code></pre>
  
  <p>There is also a repository class:</p>
  
  <pre><code>public class ProductRepo extends CouchDbRepositorySupport&lt;Product&gt; { ....
  </code></pre>
  
  <p>The repository class has a method:</p>
  
  <pre><code>public List&lt;DocumentOperationResult&gt; executeBulk( Set&lt;Product&gt; bulk ) {
      return db.executeBulk( bulk );
  }
  </code></pre>
  
  <p>The method is used for creating and updating items. Creation goes well. But on update, Ektorp throws this exception:</p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: cannot set id, id already set
      at org.ektorp.support.CouchDbDocument.setId(CouchDbDocument.java:39)
  ... 18 more
  </code></pre>
  
  <p>What I'm doing is sending a set of objects that were initially fetched by a view in the same repository - and of course the objects do have a not-null Id. This of course should not happen, since the object does have an id and must be updated, not created. According to Ektorp documentation, the db.executeBulk should handle both creating and updating documents.</p>
  
  <p>The exception is being thrown in CouchDbDocument.setId:</p>
  
  <pre><code>@JsonProperty("_id")
  public void setId(String s) {
    Assert.hasText(s, "id must have a value");
    if (id != null &amp;&amp; id.equals(s)) {
      return;
    }
    if (id != null) {
      throw new IllegalStateException("cannot set id, id already set");
    }
    id = s;
  }
  </code></pre>
  
  <p>But why ? The object sent do indeed have the Id set (revision is set too), so Ektorp should detect that we're talking about existing objects and not try to generate a new id for them. Anyone know how to this can be fix, or is the solution to ditch Ektorp and go for pure json over http in this case ?</p>
  
  <p>(Project running on Jboss 7.1.1.Final, CouchDB 1.2.0, Ektorp 1.2.2)</p>