Hibernate 搜索,查询关联
Hibernate search , querying on associations
我是 Hibernate 搜索的新手,谁能建议我如何查询嵌入式实体(一对多)
@Indexed
@Entity
public class EventDetails implements Serializable
{
@OneToMany( cascade = CascadeType.ALL )
@IndexedEmbedded
@JoinColumn( name = "event_id" )
private Set<Batches> batches;
--setter and getter--
}
和
@Entity
@Indexed
public class Batches
{
@Column( name = "batch" )
private String batch;
@ManyToOne
@ContainedIn(mappedBy="batches")
private EventDetails eventDetails;
--setter and getter--
}
服务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;
}
现在如果我必须在 "batch" 属性 上批量实现全文查询 table ,我应该将什么作为参数传递给 "onField()" 方法我的服务??
谢谢!
我是 Hibernate 搜索的新手,谁能建议我如何查询嵌入式实体(一对多)
@Indexed
@Entity
public class EventDetails implements Serializable
{
@OneToMany( cascade = CascadeType.ALL )
@IndexedEmbedded
@JoinColumn( name = "event_id" )
private Set<Batches> batches;
--setter and getter--
}
和
@Entity
@Indexed
public class Batches
{
@Column( name = "batch" )
private String batch;
@ManyToOne
@ContainedIn(mappedBy="batches")
private EventDetails eventDetails;
--setter and getter--
}
服务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;
}
现在如果我必须在 "batch" 属性 上批量实现全文查询 table ,我应该将什么作为参数传递给 "onField()" 方法我的服务??
谢谢!