0

I am using Hibernate Search with Spring Boot to create a searchable rest api. Trying to POST an instance of "Training", I receive the following stack traces. None of the two are very insightful to me which is why I am reaching out for help.

Stack trace: https://pastebin.com/pmurg1N3

It appears to me that it is trying to index a null entity!? How can that happen? Any ideas?

The entity:

@Entity @Getter @Setter @NoArgsConstructor
@ToString(onlyExplicitlyIncluded = true)
@Audited @Indexed(index = "Training")
@AnalyzerDef(name = "ngram",
    tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class ),
    filters = {
      @TokenFilterDef(factory = StandardFilterFactory.class),
      @TokenFilterDef(factory = LowerCaseFilterFactory.class),
      @TokenFilterDef(factory = StopFilterFactory.class),
      @TokenFilterDef(factory = NGramFilterFactory.class,
        params = {
          @Parameter(name = "minGramSize", value = "2"),
        } 
      )
    }
)
@Analyzer(definition = "ngram")
public class Training implements BaseEntity<Long>, OwnedEntity {

    @Id
    @GeneratedValue
    @ToString.Include
    private Long id;

    @NotNull
    @RestResourceMapper(context = RestResourceContext.IDENTITY, path = "/companies/{id}")
    @JsonProperty(access = Access.WRITE_ONLY)
    @JsonDeserialize(using = RestResourceURLSerializer.class)
    private Long owner;

    @NotNull
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String name;

    @Column(length = 10000)
    private String goals;

    @Column(length = 10000)
    private String description;

    @Enumerated(EnumType.STRING)
    @Field(index = Index.YES, store = Store.YES, analyze = Analyze.NO, bridge=@FieldBridge(impl=EnumBridge.class))
    private Audience audience;

    @Enumerated(EnumType.STRING)
    @Field(index = Index.YES, store = Store.YES, analyze = Analyze.NO, bridge=@FieldBridge(impl=EnumBridge.class))
    private Level level;

    @ManyToMany
    @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
    @NotNull @Size(min = 1)
    @IndexedEmbedded
    private Set<ProductVersion> versions;

    @NotNull
    private Boolean enabled = false;

    @NotNull
    @Min(1)
    @IndexedEmbedded
    @Field(index = Index.YES, store = Store.YES, analyze = Analyze.NO)
    @NumericField
    private Integer maxStudents;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    private Agenda agenda;

    @NotNull
    @Min(1)
    @Field(index = Index.YES, store = Store.YES, analyze = Analyze.NO)
    @NumericField
    private Integer durationDays;

    @IndexedEmbedded
    @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
    @ManyToMany(cascade = CascadeType.PERSIST)
    private Set<Tag> tags = new HashSet<>();

1 Answer 1

1

I'd say either your versions collection or your tags collection contains null objects, which is generally not something we expect in a Hibernate ORM association, and apparently not something Hibernate Search expects either.

Can you check that in debug mode?

Sign up to request clarification or add additional context in comments.

2 Comments

That was the case, indeed, and should not happen in the first place. Which line from the stack trace was the indicator for you? This way I can find out myself next time.
Well I know the Hibernate Search codebase, so I cheated, but this one helped me: Caused by: java.lang.IllegalStateException: Could not get property value and just below: at org.hibernate.search.util.impl.ReflectionHelper.getMemberValue(ReflectionHelper.java:94). So the NPE happened while getting the value of a member, which means the source object was null, as you correctly inferred. And below, at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.buildDocumentFieldsForEmbeddedObjects tells us this happened while processing an @IndexedEmbedded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.