I'm having problems constructing a query in an inheritance hierarchy. Here's a schematic of the classes involved (non-relevant annotations omitted):
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
class BasicEntity {
@Id
private int id;
}
@Entity
@Indexed
class Person extends BasicEntity {
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
private String name;
}
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(...)
class EntityRelation<O extends BasicEntity> {
@Id
private int id;
@IndexedEmbedded
@OneToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.EAGER)
@JoinColumn(...)
private BasicEntity owner;
}
@Indexed
@Entity
@DiscriminatorValue(...)
class Insurant extends EntityRelation<Person> {
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.YES)
private String insuranceNumber;
}
Now I would like to find an Insurant using the name of its inherited owner (a BasicEntity). But I can't get this to work, no matter whether I use the Lucene Query API or the Hibernate DSL API. Here's the sort of thing I've been trying:
Code:
FullTextSession session = org.hibernate.search.Search.getFullTextSession(getSession());
QueryBuilder qb1 = session.getSearchFactory().buildQueryBuilder().forEntity(Insurant.class).get();
org.apache.lucene.search.Query query1 =
qb1.keyword().
onField("owner.name").
matching("Bill").
createQuery();
FullTextQuery ftq = session.createFullTextQuery(query1);
List result = ftq.list();
The above code gets an exception:
Quote:
org.hibernate.search.SearchException: Unable to find field owner in my.class.Insurant
I've also tried any number of variations of the above, including indexing the superclasses.
Is there any way of accomplishing this?