# Tried to implement @AssociationInverseSide but no success

**URL:** <https://discourse.hibernate.org/t/tried-to-implement-associationinverseside-but-no-success/7434>\
**Category:** Hibernate Search\
**Created:** [March 25, 2023, 6:56pm UTC](https://discourse.hibernate.org/t/tried-to-implement-associationinverseside-but-no-success/7434 "2023-03-25T18:56:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![horvoje](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/horvoje/32/779_2.png) [@horvoje](https://discourse.hibernate.org/u/horvoje)\
**Post date:** [March 25, 2023, 6:56pm UTC](https://discourse.hibernate.org/t/tried-to-implement-associationinverseside-but-no-success/7434/1 "2023-03-25T18:56:00Z")

</div>

Here lays explanation how to do it and I did reading at least 3 times:  
**[Hibernate Search 6.1.8.Final: Reference Documentation  
 ](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#mapper-orm-reindexing-associationinverseside)**

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

What am I doing wrong?

* * *

**Article.java**

```auto
@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**

```auto
@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;
}

```

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [March 27, 2023, 6:33am UTC](https://discourse.hibernate.org/t/tried-to-implement-associationinverseside-but-no-success/7434/2 "2023-03-27T06:33:37Z")

</div>

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](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#section-custom-bridges), 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`](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#section-field-bridge) instead, and [declare your dependencies](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#mapper-orm-bridge-bridgedelement-dependencies) appropriately.

---

<div class="post-metadata">

**Author:** ![horvoje](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/horvoje/32/779_2.png) [@horvoje](https://discourse.hibernate.org/u/horvoje)\
**Post date:** [April 3, 2023, 3:07pm UTC](https://discourse.hibernate.org/t/tried-to-implement-associationinverseside-but-no-success/7434/3 "2023-04-03T15:07:20Z")

</div>

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

```auto
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
				)
}

```
