關於Hibernate的 Batch update returned unexpected row count from update異常

來源:互聯網
上載者:User

ERROR [http-8080-Processor22] (BatchingBatcher.java:60) - Exception executing batch:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
 查了很多資料,沒有人能說清楚這個異常是如何產生的。

在Hibernate映射一對多,多對一,多對多的時候新增常常會出現這個異常,代碼如下:

public void saveFunctionCell(FunctionCell functionCell, Integer pid) {
  System.out.println("現在進行新增操作");
  FunctionCell fc = new FunctionCell();
    try {
   BeanUtils.copyProperties(fc, functionCell);
  } catch (IllegalAccessException e) {
   e.printStackTrace();
  } catch (InvocationTargetException e) {
   e.printStackTrace();
  }
  fc.setFuncCellID(null);
  // 獲得父許可權
  FunctionCell pfc = functionCellDao.findFunctionCellByID(pid);
  fc.setParentFunctionCell(pfc);
  functionCellDao.saveFunctionCell(fc);
 }

注意特別標識出來的這個地方,BeanUtils拷貝Bean屬性的時候,它會將你的Integer類型全部設定成0,在這裡設定一個空,這樣就不會拋出錯誤了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.