Tried to implement @AssociationInverseSide but no success

Here lays explanation how to do it and I did reading at least 3 times:
Hibernate Search 6.1.8.Final: Reference Documentation

Once I make a change to Manufacturer entity, Articles having this Manufacturer are not reindexed.

What am I doing wrong?


Article.java

@Entity @Indexed
class Article {
    private Integer id;

    @Embedded
    @AttributeOverride( name = "data",
        column = @Column(name = "name", columnDefinition = "TEXT")
    )
    @FullTextField( projectable = Projectable.NO, searchable = Searchable.YES,
        analyzer = "customAnalyzer",
        valueBridge = @ValueBridgeRef(type = LocalizedFieldBridge.class)
    )
    private LocalizedField name;

    @ManyToOne(fetch = FetchType.LAZY)
    @IndexedEmbedded
    @AssociationInverseSide(
        inversePath = @ObjectPath(@PropertyValue(propertyName = "articles"))
    )
    private Manufacturer manufacturer;
}

Manufacturer.java

@Entity @Indexed
class Manufacturer  {
    private Integer id;

    @Embedded
    @AttributeOverride( name = "data",
        column = @Column(name = "name", columnDefinition = "TEXT")
    )
    @FullTextField( projectable = Projectable.NO, searchable = Searchable.YES,
        analyzer = "customAnalyzer",
        valueBridge = @ValueBridgeRef(type = LocalizedFieldBridge.class)
    )
    private LocalizedField name;


    @OneToMany(fetch = FetchType.LAZY)
    @AssociationInverseSide(
        inversePath = @ObjectPath(@PropertyValue(propertyName = "manufacturer"))
    )
    private List<Article> articles;
}

If your application starts, Hibernate Search probably understood what you did. That being said you should need to put the annotation on both sides, one would be enough; but I guess it doesn’t hurt.

Your main problem, I think, is that you’re mapping LocalizedField with a ValueBridge. Value bridges cannot handle mutable data, so if your change is within LocalizedField (e.g. manufacturer.getName().setFrench("foo"), Hibernate Search simply won’t detect that change.

You should use a PropertyBridge instead, and declare your dependencies appropriately.

1 Like

Oh I see. Class LocalizedField is not mutable as I created only constructor and getter without any setter, but I guess there is no way that Hibernate could know that.
Inside constructor I create unmodifiable map to be sure it’s immutable.

I’ll give PropertyBridge another chance. The last time I tried to implement that bridge - it was a total failure LOL (my fault, not Hibernate Search fault).

public LocalizedField( final LocalizedFieldDTO src ) {
	this.data =
		src.getData().entrySet().stream()
			.map(entry -> {
				if (entry.getValue() == null) { entry.setValue(""); }
				return entry;
			})
			.collect(
				Collectors.collectingAndThen(
					Collectors.toMap(entry ->
						Locale.forLanguageTag( entry.getKey() ),
						Map.Entry::getValue
					),
					Collections::unmodifiableMap
				)
}