我在尝试这个东西时无处可寻。我的要求是按他们的名字搜索记录
以下是我的相关课程:
记录文件夹分析.java
@Indexed
public class RecordFolderAnalysis extends AuditableEntity implements Serializable {
@ManyToOne
@JoinColumn(name = "arrivalId", nullable = false)
@ContainedIn
private RecordFolderArrival recordFolderArrival;
}
RecordFolderArrival.java
@Indexed
public class RecordFolderArrival extends BaseEntity implements Serializable
{
@Column(name="recordName", unique = true, nullable = false)
@Field(index = Index.UN_TOKENIZED)
private String recordName;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "recordFolderArrival", fetch = FetchType.LAZY, targetEntity = RecordFolderAnalysis.class)
@IndexedEmbedded
private List<RecordFolderAnalysis> recordFolderAnalysis=new ArrayList<>();
}
以下是我的 DAO 类方法:
@Override
public List<T> search(final String queryString, final String... fields) {
List searchResult = hibernateTemplate.executeFind(new HibernateCallback<Object>() {
org.hibernate.Query fullTextQuery1 = null;
@Override
public Object doInHibernate(Session session) throws HibernateException, SQLException {
try {
System.out.println("in do in hibernate");
FullTextSession fullTextSession = Search.getFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
QueryBuilder builder=fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(persistentClass).get();
Query luceneQuery=builder.keyword().onField("recordFolderArrival.recordName").matching(queryString).createQuery();
fullTextQuery1 = fullTextSession.createFullTextQuery(luceneQuery);
for (Object o : fullTextQuery1.list()) {
System.out.println("Values" + o);
}
} catch (Exception e) {
e.printStackTrace();
}
return fullTextQuery1.list();
}
});
return searchResult;
}
因此,我通过将字段名称设置为 recordFolderArrival.recordName 来按 Record-Name 进行搜索。但它抛出一个异常说
RecordFolderArrival.recordName 字段在 RecordFolderAnalysis 中不存在。
我对 Hibernate Search 很陌生,所以如果有人可以帮助我解决这个问题。谢谢,不要担心@Entity 和其他注释它们被放置在它们必须放置的位置,只是我没有将它们包含在代码段中。