关于: org.hibernate.StaleStateException: Batch update

在使用hibernate项目中,持久化类的ID用Long与long有很大区别!!

用long 作为id,当一个新的临时类要持久化时会报一个这种错:
Exception executing batch: org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
因为这个临时类,已经有一个id=0 (long的默认值);这时hibernate 为错认为这是一条持久化类,从而进行更新操作,故报错!!
这时把持久类的id 类型改成Long 就OK了,再create 时,临时类的id为null ,hibernate 才会正确的判断这是临时类而进行save操作!!

from: http://www.blogjava.net/mose2006/archive/2007/09/28/149034.html
Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 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) at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46) at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41) at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1690) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152) at com.sinosoft.sysframework.persistence.HibernateSQLQuery.doInHibernate(HibernateSQLQuery.java:118) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366) at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:338) at com.sinosoft.sysframework.persistence.BaseDaoHibernateImpl.queryList(BaseDaoHibernateImpl.java:224) at com.sinosoft.application.reins.persistence.hibernate.base.GrRePlanItemDaoHibernateImplBase.find(GrRePlanItemDaoHibernateImplBase.java:127) at com.sinosoft.application.reins.service.spring.GrTrialServiceSpringImpl.endorTrialDataSurrender(GrTrialServiceSpringImpl.java:9536) at com.sinosoft.application.reins.service.
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值