using hibernate-search 3.0.1.GA
I have a same problem as may others have had when trying to get indexing setup with all the fields I want when I am using inheritance.
Simple Example:
Container entity (i.e. entity that contains all other entities) I want to store the ID of this entity to be indexed off of. Meaning when searching I want this entities ID to be returned.
IMPORTANT - this is where things break this class has a set of base class entities, where nothing in the base class is really a field, only elements within the subclasses have fields.
Code:
@Entity
@Indexed(index = "someText")
@Table(name = "A")
public class A implements java.io.Serializable {
@Id
@DocumentId // lucene index id
@Column(name = "ID", unique = true, nullable = false, scale = 0)
public long getId() {
return this.id;
}
private Set<ParentB> parentItems= new HashSet<ParentB>(0);
@IndexedEmbedded
@OneToMany(fetch = FetchType.LAZY, mappedBy = "a", cascade = CascadeType.ALL)
public Set<TextItem> getTextItems() {
return this.textItems;
This is the parent entity (in this example this is the set of entities in my container above).
NOTE: there is really nothing in this class having to do with hibernate search. (Should there be????)
Code:
Entity
@Table(name = "B")
@Inheritance(strategy=InheritanceType.JOINED)
public class ParentB implements java.io.Serializable {
// mapping to map back to container class
private A a;
This is a child entity extending the parent - NOTE this is the class with the fields to be indexed.
Code:
@Entity
@Table(name="C")
public class ChildC extends ParentB {
.
.
// This is some string value that I want to index
// When I search for this string I want the ID from the container class in this example to be returned
@Column(name="VALUE", nullable=false)
@Field(index=Index.TOKENIZED)
public String getValue() {
return this.value;
}
Notice that neither the parent or child class have @Indexed. Do they need to have this? If so do I just put them in the same index? (i.e. @Indexed(index = "someText")? Do I need @Contained in anywhere (I don't think so, but I don't really understand what this does.
So why is there nothing created in my index when I view it with Luke????