title: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
body: <p>Sometimes when persisting an obj, one of its field is too large to fit into the db field, resulting in a data truncation exception. In the following code, I attempt to catch the DataException and simply empty out the field, and the resave. However I get an exception when resaving. Why does the Batch update exception occur and how do I get around it?</p>
  
  <pre>
  
   public static void save(Object obj) throws Exception{
          try{
              beginTransaction();
              getSession().save(obj);
              commitTransaction();
  
          }catch(Exception e){
              e.printStackTrace();
              rollbackTransaction();
              throw e;
          }finally{
              closeSession(); //not needed, session obtained from sf.getCurrentSession() will auto close
          }
      }   
   public static void saveXXX(XXX rec){
  
          try {
              save(rec);
          } catch (org.hibernate.exception.DataException e) {
              e.printStackTrace();
  
              saveXXX(rec, e); //causes an exception      
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
      private static void saveXXX(WhoisRecord rec, DataException e) {
          rec.setField(""); //empty out the problem field
          saveXXX(rec);
  </pre>
  
  <p>Exception:
  <Pre>
  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:85)
      at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
      at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
      at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
      at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
      at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
      at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
      at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2382)
      at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)
      at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
      at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
  .
  .
  .
  </pre></p>