我的代碼具有類Credenciada從類Cadastro具有atributte(嵌套類)CEP類型的「CEP」繼承。 CEP類的分支「uf」爲字符串類型。@SortableField沒有嵌套實體工作
uf atributte使用@SortableField進行了註釋,因此索引使用「cep.uf」名稱進行保存。但是當我需要按「cep.uf」排序時,會拋出一個NullPointerException異常,因爲Hibernate搜索沒有找到這個索引/分支。
OBS:我看到類IndexedTypeDescriptorImpl的屬性「allFieldDescriptors」沒有「cep.uf」的併發性。因爲此方法的第139行在此處返回null「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的哪個版本?這可能是一個已經解決的問題。 – Sanne
版本5.7.0.CR1,同時等待5.7.0.Final版本。 謝謝桑恩。我在http://in.relation.to/sanne-grinovero/index.html關注你的帖子。 – adyjr
我剛剛證實這是一個錯誤。我們將努力,謝謝:https://hibernate.atlassian.net/browse/HSEARCH-2587 –