Reputation: 922
I am new to Hibernate search , can anyone suggest me how to query on Embedded entities (one to many)
@Indexed
@Entity
public class EventDetails implements Serializable
{
@OneToMany( cascade = CascadeType.ALL )
@IndexedEmbedded
@JoinColumn( name = "event_id" )
private Set<Batches> batches;
--setter and getter--
}
and
@Entity
@Indexed
public class Batches
{
@Column( name = "batch" )
private String batch;
@ManyToOne
@ContainedIn(mappedBy="batches")
private EventDetails eventDetails;
--setter and getter--
}
Service class
public List<EventDetails> search()
{
fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(getEntityManager());
QueryBuilder q = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(EventDetails.class).get();
org.apache.lucene.search.Query luceneQuery = q.keyword().wildcard().onField("").matching(text).createQuery();
javax.persistence.Query jpaQuery = fullTextEntityManager.createFullTextQuery(luceneQuery, EventDetails.class);
List<EventDetails> list = jpaQuery.getResultList();
return list;
}
Now if i have to implement a full text query on "batch" property in batches table , what should i pass as a parameter to the "onField()" method in my service??
Thanks !
Upvotes: 4
Views: 592