title: Jersey JAX-RS auto-generated webservices and MSSQL Identity fields
body: <p>I can't get working the Jersey RESTful webservices, autogenerated with Netbeans.</p>
  
  <p>When POSTing the JSON like this,</p>
  
  <pre><code>{"name":"Some New Site"}
  </code></pre>
  
  <p>the POST query returns me this,</p>
  
  <pre><code>Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert
  explicit value for identity column in table 'site' when IDENTITY_INSERT is set to OFF.
  Error Code: 544
  Call: INSERT INTO site (id, name) VALUES (?, ?)
      bind =&amp;gt; [2 parameters bound]
  </code></pre>
  
  <p>Unlike MySQL, MSSQL doesn't generate new autoincremented ID when the NULL value is passed in INSERT query; it needs the ID field not to mentioned at all to generate value for it.</p>
  
  <p>(IDENTITY_INSERT will not make ID to be generated either)</p>
  
  <p><strong>How do I teach my Jersey services to omit the id field in INSERT query?</strong></p>
  
  <p><strong>edit:</strong> here's the POJO, it was generated automatically for me by Netbeans with it's "Restful Web Services From Database" wizard. (I am trying to be as little original as possible)</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package ru.fedd.entities;
  
  import java.io.Serializable;
  import java.util.Collection;
  import javax.persistence.Basic;
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.NamedQueries;
  import javax.persistence.NamedQuery;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import javax.xml.bind.annotation.XmlRootElement;
  import javax.xml.bind.annotation.XmlTransient;
  
  /**
   *
   * @author fkravchenko
   */
  @Entity
  @Table(name = "site")
  @XmlRootElement
  @NamedQueries({
      @NamedQuery(name = "Site.findAll", query = "SELECT s FROM Site s"),
      @NamedQuery(name = "Site.findById", query = "SELECT s FROM Site s WHERE s.id = :id"),
      @NamedQuery(name = "Site.findByName", query = "SELECT s FROM Site s WHERE s.name = :name")})
  public class Site implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @Basic(optional = false)
      @Column(name = "id")
      private Long id;
      @Basic(optional = false)
      @Column(name = "name")
      private String name;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "siteId")
      private Collection&lt;Document&gt; documentCollection;
  
      public Site() {
      }
  
      public Site(Long id) {
          this.id = id;
      }
  
      public Site(Long id, String name) {
          this.id = id;
          this.name = name;
      }
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      @XmlTransient
      public Collection&lt;Document&gt; getDocumentCollection() {
          return documentCollection;
      }
  
      public void setDocumentCollection(Collection&lt;Document&gt; documentCollection) {
          this.documentCollection = documentCollection;
      }
  
      @Override
      public int hashCode() {
          int hash = 0;
          hash += (id != null ? id.hashCode() : 0);
          return hash;
      }
  
      @Override
      public boolean equals(Object object) {
          // TODO: Warning - this method won't work in the case the id fields are not set
          if (!(object instanceof Site)) {
              return false;
          }
          Site other = (Site) object;
          if ((this.id == null &amp;&amp; other.id != null) || (this.id != null &amp;&amp; !this.id.equals(other.id))) {
              return false;
          }
          return true;
      }
  
      @Override
      public String toString() {
          return "ru.fedd.entities.Site[ id=" + id + " ]";
      }
  
  }
  </code></pre>