I am getting no where trying this thing .My requirement is to search records by their name
Following are my related classes:
RecordFolderAnalysis.javaCode:
@Indexed
public class RecordFolderAnalysis extends AuditableEntity implements Serializable {
@ManyToOne
@JoinColumn(name = "arrivalId", nullable = false)
@ContainedIn
private RecordFolderArrival recordFolderArrival;
}
RecordFolderArrival.javaCode:
@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<>();
}
Follwing is my DAO class method:Code:
@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;
}
So I am searching by Record-Name by setting field name as recordFolderArrival.recordName. But It is throwing an exception saying
Quote:
recordFolderArrival.recordName field does'nt exist in RecordFolderAnalysis.
I am very new to Hibernate Search so if anyone can help me working this thing out. Thanks and Don't worry about @Entity and other annotation they are placed where they have to be its just I have not included them in snippet.