【发布时间】:2010-11-23 14:07:51
【问题描述】:
我收到了来自 Web 应用程序(JBoss、Turbine、Hibernate)的实时部署的异常。我无法重现异常,因此无法修复错误。 这是我得到的例外:
org.hibernate.exception.DataException: could not update: [com.myproject.project.mypackage.objects.MyObject#1190]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2425)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2307)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2607)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
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.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
有趣的是,当执行以下 hql 时,我得到了这个 could not update 错误:
select sum(entity.totalPrice) from Entity entity where entity.parent.id = :parentId and deleted is null
多个实体属于一个父级。 此 hql 是更大更新过程的一部分。我需要 totalPrices 的总和来更新另一个实体。是否可能无法更新是指更新过程? 我认为情况并非如此,因为错误发生在执行更新之前。更准确地说,当在保存 hql 的 Query 对象上调用 list() 方法时会发生异常。
我试图重现异常,将实体的 totalPrice 设置为 null,但这并没有给出任何异常。如果我有很多实体附加到同一个父级,并且它们的总价格超过限制,我会得到 could not insert 异常。 我不知道是什么问题。
【问题讨论】:
-
Hibernate 在执行查询之前刷新会话。 Stacktrace 清楚地表明在刷新期间发生了错误。
-
您的问题不能是执行
select sum(...),因为堆栈跟踪显示正在执行更新。更新可能已作为此 HSQL 的结果执行,但这不是数据库引发错误的语句。 -
谢谢。情况就是这样。以前的更新导致它!