2010-11-23 50 views
0

我收到來自Web應用程序(JBoss,Turbine,Hibernate)的實時部署的異常。我無法重現該異常,因此我無法修復該錯誤。 這裏是我得到異常:Hibernate DataException:無法更新

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:

select sum(entity.totalPrice) from Entity entity where entity.parent.id = :parentId and deleted is null 

一些實體屬於同一個父。 這個hql是一個更大的更新過程的一部分。我需要totalPrices的總和來更新它與另一個實體。無法更新是否有可能引用更新過程? 我不認爲這是這種情況,因爲更新執行前發生錯誤。更確切地說,當在包含hql的Query對象上調用list()方法時發生異常。

我試圖用totalPrice將實體設置爲null來重現異常,但是這並沒有給出任何異常。如果我有很多實體附加到同一父母,並且其總計價格總和超出了限制,我會得到一個無法插入異常。 我找不出什麼問題。

+1

Hibernate在執行查詢之前刷新會話。 Stacktrace明確表示在刷新期間發生錯誤。 – axtavt 2010-11-23 14:12:01

回答

0

我覺得第一個屬性名應該是entity.parent_identity.deleted而不是簡單的刪除。 應該是這樣的最終查詢......

select sum(entity.totalPrice) from Entity entity where entity.parent_id = :parentId and entity.deleted is null 

確保PARENT_ID屬性名稱是正確的。