I have:
A Request
entity has a collection of Stage
s and each stage has a collection of StageItem
s. Stage items can be of several types and I use for them in JPA/Hibernate SINGLE_TABLE
as inheritance strategy with a discriminator column.
I need my lucene query to return requests that have a particular detail in a stage item of type A (field aDetail
in class StageItemA
). I cannot get hibernate search to see the field aDetail
in the subclass StageItemA
.
So this lucene query does not work (returns 0 results):
stages.stageItems.aDetail:blah
But searching based on fields in StageItem
works:
stages.stageItems.comment:yuppie
Using Luke, I can the fields from StageItem
, like stages.stageItems.comment
, but no field from StageItemA
, like stages.stageItems.aDetail
.
Entity definitions:
@Entity
@Table(name = "REQUEST")
@Indexed(index = "RequestIndex")
class Request implements Serializable {
//...
@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
@MapKeyColumn(name = "type", length = 50, nullable = false)
@JoinTable(
name = "REQUEST_STAGE",
joinColumns = @JoinColumn(name = "REQUEST_ID", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "STAGE_ID", referencedColumnName = "id")
)
@IndexedEmbedded
private Map<String, Stage> stages = new HashMap<>();
//...
}
@Entity
@Table(name = "STAGE")
public class Stage implements Serializable {
//...
@OneToMany(fetch = FetchType.EAGER, targetEntity = StageItem.class, cascade = {
CascadeType.ALL,
}, orphanRemoval = true)
@JoinTable(
name = "STAGE_TO_STAGE_ITEM",
joinColumns = @JoinColumn(name = "STAGE_ID"),
inverseJoinColumns = @JoinColumn(name = "STAGE_ITEM_ID")
)
@Fetch(FetchMode.JOIN)
@IndexedEmbedded
private Set<StageItem> stageItems = new HashSet<>();
//...
}
@Entity
@Table(name = "STAGE_ITEM")
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class StageItem implements Serializable {
//...
@Column(name = "TYPE")
@Field
protected String type;
@Column(name="COMMENT")
@Field
protected String comment;
//...
}
@Entity
@DiscriminatorValue(value = "A")
public class StageItemA extends StageItem {
//...
@Column(name="A_DETAIL")
@Field
private String aDetail;
//...
}