If you have an entity that is not indexed (in the code sample below: class B), but has an IndexedEmbedded annotation that includes the numeric document ID of an indexed entity (in the sample below: class A), the validation fails. Having that IndexedEmbedded annotation there is a valid scenario since the class (B) could itself be embedded by another indexed class (sample code: class C), just like you could also have other Field annotations in this non-indexed class (see someOtherStuff in the sample).
@Entity
@Indexed
public class A {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@NumericField
@SortableField
public Long getId() {
return id;
}
public void setId(final Long id) {
this.id = id;
}
private Long id;
}
@Entity
public class B {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(final Long id) {
this.id = id;
}
@OneToOne
@JoinColumn(name="a_id")
@IndexedEmbedded(includePaths="id")
public A getA() {
return a;
}
public void setA(final A a) {
this.a = a;
}
@Field
public String getSomeOtherStuff() {
return someOtherStuff;
}
public void setSomeOtherStuff(final String someOtherStuff) {
this.someOtherStuff = someOtherStuff;
}
private Long id;
private A a;
private String someOtherStuff;
}
@Entity
@Indexed
public class C {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(final Long id) {
this.id = id;
}
@OneToOne
@JoinColumn(name="b_id")
@IndexedEmbedded
public B getB() {
return b;
}
public void setB(final B b) {
this.b = b;
}
private Long id;
private B b;
}
Validation failure exception stacktrace:
Caused by: org.hibernate.search.exception.SearchException: HSEARCH000262: @NumericField annotation is used on xxx.A#id without a matching @Field annotation
at org.hibernate.search.engine.metadata.impl.NumericFieldsConfiguration.validate(NumericFieldsConfiguration.java:72)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeMemberLevelAnnotations(AnnotationMetadataProvider.java:1043)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass(AnnotationMetadataProvider.java:577)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.checkForIndexedEmbedded(AnnotationMetadataProvider.java:1812)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeMemberLevelAnnotations(AnnotationMetadataProvider.java:1031)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass(AnnotationMetadataProvider.java:577)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.doGetTypeMetadataFor(AnnotationMetadataProvider.java:174)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataForContainedIn(AnnotationMetadataProvider.java:152)
at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:346)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:202)
at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:120)
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:75)
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:521)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:880)
... 46 more
The message itself is misleading because it suggests the validation of class A fails, however the failures happens when class B is validated and the validator follows the IndexedEmbedded path to class A. |