I have two entities Restaurant
and Category
, related by a many-to-many relation. I want to search a restaurant by category_name
but i am not able to get correct results for my search, even though I can see that list is being populated correctly with the data. The entities are:
@Entity
@Table(name = "restaurant")
@Indexed
public class Restaurant implements Comparable<Restaurant> {
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "restaurant_category", joinColumns = { @JoinColumn(name = "restaurant_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "category_id", nullable = false, updatable = false) })
@IndexedEmbedded
private List<Category> listOfCategories;
}
This is the category entity
@Entity
@Table(name = "category")
@Indexed
public class Category {
@Column(name = "category_name")
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
private String categoryName;
and this my search query
Query query = queryBuilder.keyword()
.onFields("listOfCategories.categoryName").matching("Pub")
.createQuery();
org.hibernate.Query hibernateQuery = fullTextSession
.createFullTextQuery(query, Restaurant.class);
List<Restaurant> searchResults = hibernateQuery.list();
Thanks in Advance!