Я пытаюсь вставить новую сущность в свою базу данных с помощью Hibernate, проблема в том, что индекс, который должен автоматически создаваться поиском Hibernate, теперь выдает исключение AssertionFailure при поиске.
Например: при поиске csCaseNumber = 5 я получаю этот список результатов: [55,557,565], что является правильным. Но после того, как я сохраняю новую сущность с csCaseNumber = 511, а затем снова ищу csCaseNumber = 5, я получаю исключение AssertionFailure.
Но при поиске csCaseNumber = 51 я получаю правильный ответ [511],
и единственный способ получить все результаты правильно - переиндексировать все вручную.
Файл id анализируется с помощью этого пользовательского анализатора
@Entity
@Indexed
@AnalyzerDef(name = "CustomAutocompleteAnalyzer",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = EdgeNGramFilterFactory.class, params = {
@Parameter(name = "minGramSize", value = "1"),
@Parameter(name = "maxGramSize", value = "10")
}),
})
@Table(name = "table")
@XmlRootElement
public class Table implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@NotNull
@Column(name = "id")
private BigDecimal id;
@NotNull
@Size(min = 1, max = 255)
@Column(name = "cs_case_number")
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO
, analyzer = @Analyzer(definition = "CustomAutocompleteAnalyzer")
)
private String csCaseNumber;
public BigDecimal getId() {
return id;
}
public void setId(BigDecimal id) {
this.id = id;
}
public String getCsCaseNumber() {
return csCaseNumber;
}
public void setCsCaseNumber(String csCaseNumber) {
this.csCaseNumber = csCaseNumber;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof TCase)) {
return false;
}
TCase other = (TCase) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.luceneproject.pojo.TCase[ id=" + id + " ]";
}
}
Способ, которым сохраняются новые сущности
public void addNewFall() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("com.luceneProject_LuceneProject_war_1.0-SNAPSHOTPU");
if (fallNummer2 != null && fallId != 0) {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
try {
BigDecimal bd = new BigDecimal(fallId);
TCase tcase = new TCase();
tcase.setId(bd);
tcase.setCsCaseNumber(fallNummer2);
em.persist(tcase);
em.getTransaction().commit();
} catch (Exception e) {
} finally {
em.close();
emf.close();
}
}
}
Сообщение об ошибке
Info: --------- com.luceneproject.luceneproject.FallLazyDataModel@f6fe5ee -----------------
Severe: Error Rendering View[/table2.xhtml]
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:100)
at org.hibernate.search.query.hibernate.impl.MultiClassesQueryLoader.executeLoad(MultiClassesQueryLoader.java:118)
at org.hibernate.search.query.hibernate.impl.AbstractLoader.load(AbstractLoader.java:73)
at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.doHibernateSearchList(FullTextQueryImpl.java:242)
at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.list(FullTextQueryImpl.java:225)
at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.getResultList(FullTextQueryImpl.java:124)
at com.luceneproject.luceneproject.DataService.getListfromLucene(DataService.java:168)
at com.luceneproject.luceneproject.DataService.getFallsList(DataService.java:49)
at com.luceneproject.luceneproject.FallLazyDataModel.load(FallLazyDataModel.java:30)
at org.primefaces.component.datatable.DataTable.loadLazyData(DataTable.java:573)
at org.primefaces.component.datatable.feature.FilterFeature.encode(FilterFeature.java:140)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:88)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:949)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1912)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:638)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:874)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIForm.visitTree(UIForm.java:395)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:423)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:342)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:63)
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1124)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1905)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:465)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:194)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:126)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:223)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1540)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:748)
Я использую Hibernate Search версии 5.11