Reputation: 1080
My code has the class Credenciada that inherits from class Cadastro that has the atributte(nested class) "cep" of CEP type. The CEP class has the atributte "uf" of String type.
The uf atributte was annoted with @SortableField, so the index is save with "cep.uf" name. But when I need sort by "cep.uf" a NullPointerException is throwed, because the Hibernate-search didn't find this index/atributte.
OBS: I saw that attribute "allFieldDescriptors" of class IndexedTypeDescriptorImpl didn't have the "cep.uf" ocurrency. Because in line 139 of this method returns null on this point "return allFieldDescriptors.get(fieldName)".
Cadastro.java:
@Entity
@Table(name = "CAD")
@Inheritance(strategy = InheritanceType.JOINED)
@Indexed
public class Cadastro extends Entidade<Long> {
@Id
private Long codigo;
@IndexedEmbedded
@NotAudited
@ManyToOne
private CEP cep;
//more attrs and getters/setters here
}
Credenciada.java:
@Entity
@Indexed
@Table(name = "CAD_CRDC")
@PrimaryKeyJoinColumn(name = "CD_CAD_CRDC")
public class Credenciada extends Cadastro {
//many attrs and getters/setters here
}
CEP.java
@Entity
@Table(name = "CAD_CEP", schema = "dne")
public class CEP extends Entidade<Long> {
@Id
@Field(name = "cep", store = Store.YES)
private Long nrCep;
@SortableField
@Field(store = Store.YES)
private String uf;
}
Search code:
FullTextEntityManager fullTextEntityManager = hibernateUtil.getFullTextEntityManager();
QueryBuilder qb = HibernateSearchUtil.createQueryBuilder(fullTextEntityManager, Credenciada.class);
BooleanJunction<?> criterios = qb.bool();
//many conditions here...
org.apache.lucene.search.Query rootQuery = criterios.isEmpty() ? new MatchAllDocsQuery() : criterios.createQuery();
FullTextQuery query = fullTextEntityManager.createFullTextQuery(rootQuery, Credenciada.class);
query.setSort(qb.sort().byField("cep.uf").createSort());
List resultList = query.getResultList();
Exception:
java.lang.NullPointerException
at org.hibernate.search.query.dsl.sort.impl.SortFieldStates.getCurrentSortFieldTypeFromMetamodel(SortFieldStates.java:156)
at org.hibernate.search.query.dsl.sort.impl.SortFieldStates.determineCurrentSortFieldTypeAutomaticaly(SortFieldStates.java:149)
at org.hibernate.search.query.dsl.sort.impl.ConnectedSortContext.byField(ConnectedSortContext.java:42)
at br.gov.sindec.modulos.credenciada.repositorio.impl.CredenciadaRepositorioImpl.criarQueryListarCredenciadasIndexadas(CredenciadaRepositorioImpl.java:124)
at br.gov.sindec.modulos.credenciada.repositorio.impl.CredenciadaRepositorioImpl.listarCredenciadasIndexadas(CredenciadaRepositorioImpl.java:52)
Upvotes: 3
Views: 707
Reputation: 9977
Hibernate Search 5.6.1.Final and 5.7.0.Final have just been released; both versions include a fix for your issue (HSEARCH-2587).
Upvotes: 1