@SortableField 在嵌套实体中不起作用

@SortableField not working in nested entity

我的代码有 class Credenciada 继承自 class Cadastro 具有属性(嵌套class) "cep" CEP 类型。 CEP class 具有 String 类型的属性 "uf"。

uf 属性用@SortableField 注释,因此索引以"cep.uf" 名称保存。但是当我需要按 "cep.uf" 排序时,会抛出 NullPointerException,因为 Hibernate-search 没有找到这个 index/atributte.

OBS:我看到 class IndexedTypeDescriptorImpl 的属性 "allFieldDescriptors" 没有 "cep.uf" 货币。因为在这个方法的第 139 行 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;

}

搜索码:

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();

异常:

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)

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).