---
title: "StaleStateException和HibernateOptimisticLockingFailureExcepti"
author: "weishuwei"
date: "2007-03-10T17:44:03Z"
tags: []
slug: "stalestateexception-hibernateoptimisticlockingfailureexcepti"
draft: false
lastmod: "2007-03-10T17:44:03Z"
id: 58830
url: "https://weishuwei.iteye.com/blog/58830"
---

更新东西时出现错误,  
ERROR \[org.hibernate.jdbc.AbstractBatcher] - Exception executing batch:  
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:61)

ERROR \[com.opensymphony.webwork.dispatcher.DispatcherUtils] - Could not execute action  
 org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update \[0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update \[0]; actual row count: 0; expected: 1

备注:持久化对象的主键是我们自定义的IdGenerator.java  
解决方案:因为用到了freemarker,传入的id被freemarker默认定科学计数法定义格式如下:1,000,222,555,;我们定义id?c;这样得到的id格式如下:1000222555,问题得以解决.

后话:  
问题是解决了,但出错提示有点奇怪,这一点有待解决.