Programmatic API mapping does not recognize Hibernate Search fields inherited from parent entities annotated with @MappedSuperclass. As a consequence, Hibernate Search views the fields as unmapped, resulting in a SearchException. This is not considered a bug, but a by-design behaviour that can only be addressed by a functionality enhancement. Until the functionality is enhanced, the issue can be worked around by overriding the getter methods of the inherited fields in the child entities.
Description of problem:
Fields declared on @MappedSuperclass parent are not recognized on child entity by programmatic API mapping.
Workaround:
Overide getters on child entity.
Version-Release number of selected component (if applicable):
hibernate-search-4.1.0.Final, wfk-2.0.0.GA
How reproducible:
@MappedSuperclass
public abstract class FooAbstract {
protected String bar;
public String getBar() {
return this.bar
}
...
}
@Entity
public class Foo extends FooAbstract {}
@Factory
public SearchMapping getSearchMapping() {
SearchMapping mapping = new SearchMapping();
mapping
.entity(Foo.class).indexed()
.property("bar", ElementType.METHOD)
.field();
}
Steps to Reproduce:
1. create data model with inheritance
2. map indexes using programmatic api
3. try to get inherited field value from extended entity
Actual results:
org.hibernate.search.SearchException: Unable to find field bar in ...
Expected results:
return value of field
Additional info:
reported on jira too: https://hibernate.onjira.com/browse/HSEARCH-1108
As this is no longer considered a bug, I have moved this from known issues to resolved issues in WFK 2.2.0 Release Notes.
The information will be included in the Hibernate Search Guide in WFK 2.3.0, a cloned issue is created for the purpose.
Description of problem: Fields declared on @MappedSuperclass parent are not recognized on child entity by programmatic API mapping. Workaround: Overide getters on child entity. Version-Release number of selected component (if applicable): hibernate-search-4.1.0.Final, wfk-2.0.0.GA How reproducible: @MappedSuperclass public abstract class FooAbstract { protected String bar; public String getBar() { return this.bar } ... } @Entity public class Foo extends FooAbstract {} @Factory public SearchMapping getSearchMapping() { SearchMapping mapping = new SearchMapping(); mapping .entity(Foo.class).indexed() .property("bar", ElementType.METHOD) .field(); } Steps to Reproduce: 1. create data model with inheritance 2. map indexes using programmatic api 3. try to get inherited field value from extended entity Actual results: org.hibernate.search.SearchException: Unable to find field bar in ... Expected results: return value of field Additional info: reported on jira too: https://hibernate.onjira.com/browse/HSEARCH-1108