title: JPA SET IDENTITY_INSERT not working
body: <p>I want to run this query from JPA from my code. But its not working.</p>
  
  <p>Please help.</p>
  
  <pre><code>SET IDENTITY_INSERT "+tableName+" ON
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The exact code line is this</p>
  
  <pre><code>Query query = entityManager.createNativeQuery("SET IDENTITY_INSERT   [tableName] ON");
  int updated = query.executeUpdate();
  </code></pre>
  
  <p>It gives 0 for the updated. Does not give any error on this line execution. But when try to insert after this, it gives constraint violation exception like below.</p>
  
  <pre><code>2015-03-09 15:46:52,922 WARN  org.hibernate.util.JDBCExceptionReporter.logExceptions:233 - SQL Error: 544, SQLState: 23000
  2015-03-09 15:46:52,923 ERROR org.hibernate.util.JDBCExceptionReporter.logExceptions:234 - Cannot insert explicit value for identity column in table 'table_name' when IDENTITY_INSERT is set to OFF.
  2015-03-09 15:46:52,924 ERROR org.hibernate.event.def.AbstractFlushingEventListener.performExecutions:324 - Could not synchronize database state with session
  org.hibernate.exception.ConstraintViolationException: could not insert: [com.entities.EntityName]
  </code></pre>