title: On release of batch it still contained JDBC statements- HibernateItemWriter
body: <p>I am newbie to Spring batch.I was trying to use <code>HibernateItemWriter</code> for writing into destination database.I am getting following exception when executing my batch job. </p>
  
  <p>Following is the exception and code of my application </p>
  
  <p><code>HibernateItemWriter</code> configuration :- </p>
  
  <pre><code>@StepScope
  @Bean
  public ItemWriter&lt;NewEmployee&gt; hibernateEmployeeItemWriter() throws IOException {
          HibernateItemWriter&lt;NewEmployee&gt; itemWriter = new HibernateItemWriter&lt;&gt;();
          itemWriter.setSessionFactory(sessionFactory().getObject());
          itemWriter.setClearSession(true);
          return itemWriter;
  }
  </code></pre>
  
  <p>Session factory and Transaction Manager code</p>
  
  <pre><code>@Bean
  public LocalSessionFactoryBean sessionFactory() throws IOException{
      LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
      factoryBean.setDataSource(configuration.getDataSource());
     // factoryBean.setAnnotatedPackages("com.qiwkreport.qiwk.etl.domain");
      factoryBean.setPackagesToScan("com.qiwkreport.qiwk.etl.domain");
      factoryBean.afterPropertiesSet();
      return factoryBean;
  }
  
  
  @Bean
  public JpaTransactionManager transactionManager() {
      JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
      return jpaTransactionManager;
  }
  </code></pre>
  
  <p>Entity class code :-</p>
  
  <pre><code>    Entity
      @Table(name = "NEWEMPLOYEE")
      public class NewEmployee {
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "ID")
  private long id;
  @Column(name = "FIRSTNAME")
  private String firstName;
  @Column(name = "LASTNAME")
  private String lastName;
  @Column(name = "VILLAGE")
  private String village;
  @Column(name = "STREET")
  private String street;
  @Column(name = "CITY")
  private String city;
  @Column(name = "DISTRICT")
  private String district;
  @Column(name = "STATE")
  private String state;
  @Column(name = "PINCODE")
  private String pincode;
  @Column(name = "MANAGERID")
  private String managerid;
  @Column(name = "MANAGERNAME")
  private String managerName;
  </code></pre>
  
  <p>Exception Trace :-</p>
  
  <pre><code>       017-08-30 20:22:22.919 DEBUG 9560 --- [nio-9000-exec-7] org.hibernate.SQL                        : update NEWEMPLOYEE set CITY=?, DISTRICT=?, FIRSTNAME=?, LASTNAME=?, MANAGERNAME=?, MANAGERID=?, PINCODE=?, STATE=?, STREET=?, VILLAGE=? where ID=?
  2017-08-30 20:22:22.930  INFO 9560 --- [nio-9000-exec-7] o.h.e.j.b.internal.AbstractBatchImpl     : HHH000010: On release of batch it still contained JDBC statements
  2017-08-30 20:22:22.935 ERROR 9560 --- [nio-9000-exec-7] o.s.batch.core.step.AbstractStep         : Encountered an error executing step employeeSlaveStep in job EmployeeJob
  
  org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
      at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:67)
      at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:54)
      at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:46)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3134)
      at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3013)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3393)
      at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:145)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:582)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:456)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
      at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
      at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282)
      at org.springframework.batch.item.database.HibernateItemWriter.write(HibernateItemWriter.java:114)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
  </code></pre>