gpt4 book ai didi

java - Query.list() 中的 Hibernate NullPointerException

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:16 24 4
gpt4 key购买 nike

它仅通过以下堆栈跟踪复制了一次

Caused by: java.lang.NullPointerException at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:119) at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65) at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35) at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:970) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1115) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)

有人知道什么是原因吗?

Hibernate 版本是 3.2.7.GA

我确信原因不在当前查询中,因为每个列表都会执行。为什么flush for current session会掉下来?可以通过某种方式预防吗?

最佳答案

这是生成空指针的方法(来源:http://grepcode.com/file_/repo1.maven.org/maven2/org.hibernate/hibernate/3.2.6.ga/org/hibernate/event/def/AbstractFlushingEventListener.java/?v=source):

private void prepareEntityFlushes(EventSource session) throws HibernateException {

log.debug("processing flush-time cascades");

final Map.Entry[] list = IdentityMap.concurrentEntries( session.getPersistenceContext().getEntityEntries() );
//safe from concurrent modification because of how entryList() is implemented on IdentityMap
final int size = list.length;
final Object anything = getAnything();
for ( int i=0; i<size; i++ ) {
Map.Entry me = list[i];
EntityEntry entry = (EntityEntry) me.getValue(); //nullpointer here!
Status status = entry.getStatus();
if ( status == Status.MANAGED || status == Status.SAVING ) {
cascadeOnFlush( session, entry.getPersister(), me.getKey(), anything );
}
}
}

IdentityMap.concurrentEntries 返回一个 Map.Entry 数组,其中包含所提供 map 的条目。看起来从 session.getPersistenceContext().getEntityEntries() 的映射中返回了一个空元素,尝试获取源代码(应该可以通过大多数 IDE 获取)并调试该方法。另外,检查你的实体定义,那里可能有问题..

关于java - Query.list() 中的 Hibernate NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18073842/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com