How to resolve inverse side of the association type issue?

Here is the code snippet below and I am getting below exception at startup. Exception message is very clear but not sure where exactly(on which field) we need to put @AssociationInverseSide annotation.

Link.java

    @ManyToOne
    @Fetch(FetchMode.SELECT)
    @JoinColumn(.... )
    @ApiModelProperty
    private LinkType type;

 @JsonProperty("linkType")
    @GenericField(name = "linkType_sort",sortable = Sortable.YES)
    @FullTextField(analyzer = "lowercaseWhitespaceAnalyzer")
    @IndexingDependency(derivedFrom = @ObjectPath({
            @PropertyValue(propertyName = "type"),
            @PropertyValue(propertyName = "name")}
    ))
    public String getLinkType() {
        return type.getName();
    }

   @JsonProperty("linkType")
    public void setLinkType(final String linkType) {
        if (this.type == null) {
            this.type = new LinkType();
        }
        this.type.setName(linkType);
    }

LinkType.java

 @NaturalId(mutable = true)
    @Column(name = "name", nullable = false)
    @NotNull
    @ApiModelProperty(required = true)
    @Size(min = 3, max = 25)
    @Pattern(regexp = "\\b([a-z]+)([A-Z][a-z]+)*\\b")
    @GenericField(name="name_sort",sortable = Sortable.YES)
    @FullTextField(analyzer = "lowercaseWhitespaceAnalyzer")
    private String name;

Exception:

 Hibernate ORM mapping: 
        type 'com.xxx.xxx.model.Link': 
            path '.linkType<no value extractors>': 
                failures: 
                  - HSEARCH700020: Unable to find the inverse side of the association on type 'com.xxx.xxx.model.Link' at path '.type<no value extractors>'. Hibernate Search needs this information in order to reindex 'com.xxx.xxx.model.Link' when 'com.xxx.xxx.model.LinkType' is modified. You can solve this error by defining the inverse side of this association,  either with annotations specific to your integration (@OneToMany(mappedBy = ...) in Hibernate ORM)  or with the Hibernate Search @AssociationInverseSide annotation.

Come on, it tells you what the problematic association is right there in the error message:

So you need to define the inverse side of Link#type. Most likely a new @OneToMany(mappedBy = "type") List<Link> links association in whatever entity your type association points to (Type? LinkType?).

If defining this inverse side is not an option, you can always explicitly opt out of automatic reindexing for that association: Hibernate Search 7.0.0.Final: Reference Documentation . You’ll basically get the Hibernate Search 5 behavior for indexed transient attributes, then.

Updated Link.java - I have already @ManyToOne annotation defined but it does not have mappedBy property.

Also we don’t have List<Link> links is declared in the LinkType.
Do we need to opt out of automatic reindexing for this association then??

Sorry @yrodiere - I had placed code in incorrect file now I have updated link.java. Can you please take a look again?

Please let me know if you need complete code of both the entities.

I tried

 @AssociationInverseSide(inversePath = @ObjectPath(@PropertyValue(propertyName = "link")))
    @ApiModelProperty
    private LinkType type;

but it throws Unable to apply path '.link<default value extractors>' to type am I missing something?

Hi @yrodiere - After defining below property in LinkType.java exception going away

    @OneToMany(mappedBy = "type")
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private Set<Link> links;

Is this the solution you were talking about?? If yes, can you please provide some explanation around why it is needed in HS 6??

It’s explained right there in the error message:

More info here (the linked text is about @IndexedEmbedded, but the same reasoning applies in your case).

1 Like

Thank you very much @yrodiere again !

If I add this code then exception is going away but few existing test case are failing. However will work on try to fix it but just wanted to check is there any alternate option to resolve inverside exception without this code or @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO)?

I think test are failing because of cyclic call. Handler dispatch failed; nested exception is java.lang.StackOverflowError

If I write code like this would it reindexed??

    @JsonProperty("linkType")
    @GenericField(name = "linkType_sort",sortable = Sortable.YES)
    @FullTextField(analyzer = "lowercaseWhitespaceAnalyzer")
    @IndexingDependency(derivedFrom = @ObjectPath({
            @PropertyValue(propertyName = "type"),
            @PropertyValue(propertyName = "name")}
    ))
    @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
    public String getLinkType() {
        return type.getName();
    }