Hibernate java.lang.ClassCastException:org.hibernate.action.EntityIdentityInsertAction 无法转换为 org.hibernate.action.EntityInsertAction
我将 Hibernate 与 EntityManager 一起使用。当我使用时
Session session = (Session)entityManager.getDelegate();
session.flush();
session.clear();
,我得到
java.lang.ClassCastException: org.hibernate.action.EntityIdentityInsertAction cannot be cast to org.hibernate.action.EntityInsertAction
at org.hibernate.engine.ActionQueue$InsertActionSorter.sort(ActionQueue.java:636)
at org.hibernate.engine.ActionQueue.sortInsertActions(ActionQueue.java:369)
at org.hibernate.engine.ActionQueue.sortActions(ActionQueue.java:355)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:224)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
由于它没有说明哪个实体导致了问题,所以我被困在这里。有谁知道是什么原因造成的?
I'm using Hibernate with an EntityManager. When I use
Session session = (Session)entityManager.getDelegate();
session.flush();
session.clear();
I get
java.lang.ClassCastException: org.hibernate.action.EntityIdentityInsertAction cannot be cast to org.hibernate.action.EntityInsertAction
at org.hibernate.engine.ActionQueue$InsertActionSorter.sort(ActionQueue.java:636)
at org.hibernate.engine.ActionQueue.sortInsertActions(ActionQueue.java:369)
at org.hibernate.engine.ActionQueue.sortActions(ActionQueue.java:355)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:224)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
Since it doesn't say which entity causes the problem, I'm stuck here. Does anyone have an idea what can cause this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 Hibernate 中的一个错误。当满足以下条件时抛出异常:
identity
hibernate.order_inserts
是true
发生这种情况是因为 < code>EntityIdentityInsertAction 可以添加到
ActionQueue.insertions
列表中,而ActionQueue$InsertActionSorter
期望它只包含EntityInsertAction
。似乎尚未报告此错误,因此请随时报告。
也许您可以更改 hibernate.order_inserts 的值作为解决方法。
It's a bug in Hibernate. Exception is thrown when following conditions are met:
identity
hibernate.order_inserts
istrue
It happens because
EntityIdentityInsertAction
can be added to theActionQueue.insertions
list, whereasActionQueue$InsertActionSorter
expects that it contains onlyEntityInsertAction
s.It looks like this bug was not reported yet, so feel free to report it.
Perhaps you can change the value of
hibernate.order_inserts
as a workaround.我收到此错误只是因为我忘记在调用
em.persist(myNewEntity)
的方法上添加@Transactional
注释,因为我认为所有调用者都将在 Transaction 上,错误不会直接弹出,但是当我尝试从表中删除所有行时,
该错误确实具有误导性,但与 @axtavt 答案
所以
I got this error just because I forget to add
@Transactional
annotation on the method that callsem.persist(myNewEntity)
as I thought all the callers will be on Transaction,the error is not popping directly but when I tried to delete all rows from a table
really the error is misleading but its the same as the second case in @axtavt answer
so