升级后将Hibernate搜索4.3.0.Final升级到5.7.0.Final和当前的hibernate版本为5.2.6.Final
我遇到了以下异常
Caused by: org.hibernate.search.exception.AssertionFailure: An entity got loaded even though it was not part of the EntityInfo list
at org.hibernate.search.query.hibernate.impl.CriteriaObjectInitializer.initializeObjects(CriteriaObjectInitializer.java:98)
at org.hibernate.search.query.hibernate.impl.QueryLoader.executeLoad(QueryLoader.java:88)
at org.hibernate.search.query.hibernate.impl.AbstractLoader.load(AbstractLoader.java:58)
at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.list(FullTextQueryImpl.java:207)
at com.anite.bof2.component.textsearch.impl.TextSearcher.runQuery(TextSearcher.java:50)
at com.anite.bof2.component.textsearch.impl.DefaultLuceneTextSearch.performInclusiveTextSearch_aroundBody0(DefaultLuceneTextSearch.java:72)
at com.anite.bof2.component.textsearch.impl.DefaultLuceneTextSearch$AjcClosure1.run(DefaultLuceneTextSearch.java:1)
at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96cproceed(AbstractTransactionAspect.aj:66)
at org.springframework.transaction.aspectj.AbstractTransactionAspect$AbstractTransactionAspect$1.proceedWithInvocation(AbstractTransactionAspect.aj:72)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(AbstractTransactionAspect.aj:70)
at com.anite.bof2.component.textsearch.impl.DefaultLuceneTextSearch.performInclusiveTextSearch(DefaultLuceneTextSearch.java:32)
at com.anite.bof2.modules.actions.query.SearchTextAction.update(SearchTextAction.java:285)
at com.anite.bof2.modules.actions.BaseBof2PenguinAction.doPerform(BaseBof2PenguinAction.java:31)
at org.apache.turbine.modules.actions.VelocityAction.doPerform(VelocityAction.java:99)
at org.apache.turbine.util.velocity.VelocityActionEvent.perform(VelocityActionEvent.java:177)
at org.apache.turbine.modules.actions.VelocityAction.perform(VelocityAction.java:187)
at org.apache.turbine.modules.actions.VelocitySecureAction.perform(VelocitySecureAction.java:133)
at org.apache.turbine.modules.ActionLoader.exec(ActionLoader.java:148)
at org.apache.turbine.modules.pages.DefaultPage.doBuild(DefaultPage.java:215)
at org.apache.turbine.modules.Page.build(Page.java:125)
at org.apache.turbine.modules.PageLoader.exec(PageLoader.java:151)
at org.apache.turbine.pipeline.ExecutePageValve.executePage(ExecutePageValve.java:158)
at org.apache.turbine.pipeline.ExecutePageValve.invoke(ExecutePageValve.java:101)
... 48 more
以下是提供异常的代码块
@Transactional(readOnly = true)
public <T> TextResults<T> performExclusionTextSearch(TextArgs<T> args)
{
if (args != null && args.getSearchText() != null && args.getFromDate() != null && args.getToDate() != null
&& args.getFields() != null)
{
FullTextSession fullTextSession = Search.getFullTextSession(sessionFactory.getCurrentSession());
QueryBuilder qb = getQueryBuilder(fullTextSession, args.getSearchEntity());
try
{
// exclusion query
Query query = qb
.bool()
.must(qb.keyword().onFields(args.getFields()).matching(args.getSearchText()).createQuery())
.not()
.must(qb.range().onField("captureDate").from(args.getFromDate()).to(args.getToDate())
.createQuery()).createQuery();
FullTextQuery textQuery = fullTextSession.createFullTextQuery(query, args.getSearchEntity());
// apply any filter
if (args.getFilter() != null)
{
textQuery.enableFullTextFilter(args.getFilterClass()).setParameter(args.getFilterField(),
args.getFilter());
}
return runQuery(textQuery, args.getLimit());
}
catch (EmptyQueryException e)
{
// lucene standardanalyser filtered out the query word - ignore
}
return new TextResults<T>(false, new ArrayList<T>(0));
}
else
{
ManagementContext.logErrorEvent("Null parameters passed to text search");
return new TextResults<T>(false, new ArrayList<T>(0));
}
}
protected <T> TextResults<T> runQuery(FullTextQuery query, int limit)
{
boolean moreDataAvailable = false;
//apply capturedate as a sorted field
Sort sort = new Sort(new SortField("captureDate", SortField.Type.LONG, true));
query.setSort(sort);
int resultsize = query.getResultSize();
if(resultsize > limit)
{
//return marker to indicate more results available
moreDataAvailable = true;
query.setMaxResults(limit);
}
@SuppressWarnings("unchecked")
List<T> data = query.getResultList();
TextResults<T> results = new TextResults<>(moreDataAvailable, data);
return results;
}
在runQuery方法中执行以下行时出错。
@SuppressWarnings("unchecked")
List<T> data = query.getResultList();
我的数据库是Oracle 11g。上面的代码工作正常,并通过Hibernate搜索4.3.0.Final提供有效的输出。
答案 0 :(得分:0)
老实说,你正在更新这样一个古老的版本,我很惊讶你的应用程序甚至已经过去了:)
在尝试分析与搜索相关的失败之前,您应该做两件事:
答案 1 :(得分:0)
虽然在从4.3.0.Final升级到5.7.0.Final期间调查类似问题,但发现了断言异常的可能原因: -
org.hibernate.search.exception.AssertionFailure: An entity got loaded even though it was not part of the EntityInfo list
当搜索条件中使用的类错误地重写其equals()
和hashCode()
方法以在身份而不是值上进行比较时,可能会抛出异常。这导致Hibernate代码的LinkedHashMap.put(key, value)
方法无法找到它期望在映射中的临时代理对象(之前放置在那里),因为key
将包含具有不同的对象实例相同的价值。