问题
After upgrading Hibernate search 4.3.0.Final to 5.7.0.Final and current hibernate version is 5.2.6.Final
I got following exception
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
Below is the code block which gives exception
@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;
}
I got error when executing below line in runQuery method.
@SuppressWarnings("unchecked")
List<T> data = query.getResultList();
My database is Oracle 11g. Above code is working fine and gives valid output with Hibernate search 4.3.0.Final.
回答1:
Honestly, you're updating from such an ancient version that I'm amazed your application even got past startup :)
Two things you should do before even trying to analyze the Search-related failures:
- make sure you're using a recent enough version of Hibernate ORM. In this case it should be at least ORM 5.2.3, and I'd recommend the latest (5.2.10 as I'm writing this).
- reindex your database completely. Hibernate Search changed a lot since 4.3, so your older indexes are very unlikely to work with Hibernate Search 5.7.
回答2:
Whilst investigating a similar issue during an upgrade from 4.3.0.Final to 5.7.0.Final, have found a possible cause for the assertion exception:-
org.hibernate.search.exception.AssertionFailure: An entity got loaded even though it was not part of the EntityInfo list
The exception can be thrown when the class being used in the search criteria has incorrectly overridden its equals()
and hashCode()
methods to compare on identity rather than by value. This causes the Hibernate code's LinkedHashMap.put(key, value)
method to fail to find the temporary proxy object that it expects to be in the map (that it had previously placed there) because the key
will contain different object instances that have the same value.
来源:https://stackoverflow.com/questions/45993788/after-upgariding-hibernate-search-4-3-to-5-7-0-text-search-is-not-working