We're updating the issue view to help you get more done. 

Validation of IndexedEmbedded targeting a numeric document ID fails inside a non-indexed entity

Description

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).

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 @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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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.

Environment

None

Status

Assignee

Yoann Rodière

Reporter

Marco Perazzo

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Fix versions

Affects versions

5.6.0.CR1

Priority

Major