title: Can't insert into Sql Server using Spring Framework SimpleJdbcInsert
body: <p>I'm trying to insert a row in Sql Server 2008 using JDBC Spring framework:</p>
  
  <p>Here is the code:</p>
  
  <pre><code>BdClass bdclass= new BdClass(BdClass.BdConfig.ConnectionString_MYHOME);
  Person personaNueva = new Person();
  personaNueva.setIdPerson(5);
  personaNueva.setUsuario("JavaUser");
  personaNueva.setClave("JavaPassword");
  personaNueva.setNombre("JavaNombreUsuario");
  personaNueva.setActivo("S");
  personaNueva.AddPerson(bdclass); 
  
  
  //Person class
  
  public void AddPerson(BdClass bdclass)
  {
      Map&lt;String, Object&gt; parameters = new HashMap&lt;String, Object&gt;();
      parameters.put(Constantes.idperson, this.getIdperson());
      parameters.put(Constantes.usuario,this.getUsuario());
      parameters.put(Constantes.clave,this.getClave());
      parameters.put(Constantes.nombre,this.getNombre());
      parameters.put(Constantes.activo, this.getActivo());
      bdclass.Insert(parameters,Constantes.Table_Name);
  }
  
     //BdClass Insert
  </code></pre>
  
  <blockquote>
    <p>In this step I am enabling IDENTITY INSERT</p>
  </blockquote>
  
  <pre><code>public void Insert(Map&lt;String, Object&gt; parameters, String TableName)
     {
        this.jdbcTemplate.execute("SET IDENTITY_INSERT " + TableName + " ON");
        JdbcInsert = new SimpleJdbcInsert(this.jdbcTemplate).withTableName(TableName);        
          JdbcInsert.execute(parameters); 
  
      }
  </code></pre>
  
  <p>When running the execute statement I am getting the following exception:</p>
  
  <blockquote>
    <p>Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot
    insert explicit value for identity column in table 'Persons' when
    IDENTITY_INSERT is set to OFF</p>
  </blockquote>
  
  <p>I have already tried the command <strong>SET IDENTITY_INSERT PERSONS ON</strong> in sql management studio with no luck.</p>
  
  <p><strong>EDIT: idperson field is identity</strong>, but it doesn't matter if I pass the parameter and value or not... I'm getting the same error</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Ok, I fixed it by using the usingColumns Property, So I can specify every column:</p>
  
  <pre><code>public void Insert(Map&lt;String, Object&gt; parameters, String TableName)
  {       
    this.jdbcTemplate.execute("SET IDENTITY_INSERT " + TableName + " OFF");
    JdbcInsert = new SimpleJdbcInsert(this.jdbcTemplate).withTableName(TableName)
      .usingColumns(Person.Constantes.usuario,Person.Constantes.clave,
      Person.Constantes.nombre,Person.Constantes.activo);
  
    JdbcInsert.execute(parameters);
  }   
  </code></pre>