# Index not updated after updating IndexedEmbedded collections

**URL:** <https://discourse.hibernate.org/t/index-not-updated-after-updating-indexedembedded-collections/1259>\
**Category:** Hibernate Search\
**Created:** [August 18, 2018, 5:26pm UTC](https://discourse.hibernate.org/t/index-not-updated-after-updating-indexedembedded-collections/1259 "2018-08-18T17:26:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali\_Shahbazi](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ali_shahbazi/32/255_2.png) [@Ali\_Shahbazi](https://discourse.hibernate.org/u/Ali_Shahbazi)\
**Post date:** [August 18, 2018, 5:26pm UTC](https://discourse.hibernate.org/t/index-not-updated-after-updating-indexedembedded-collections/1259/1 "2018-08-18T17:26:33Z")

</div>

I have three entities linked with IndexedEmbedded.

If I add or remove entity IndexEmbedded relation index on master entity get Not updated.  
Should I rebuild master index manually?

In version 5.9.2

[testCase](https://drive.google.com/open?id=1PpURLu0v7DB5Mgr4F6QIe7QHY34d5Q-l)

```auto
@Entity
@Indexed
@Table(name = "[a]")
public class A implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "[id]")
    private Integer id;

    @Column(name = "[title]")
    private String title;

    @IndexedEmbedded(includeEmbeddedObjectId = true, includePaths = {"id","c.id"})
    @OneToMany(mappedBy = "a", fetch = FetchType.LAZY)
    private Collection<B> bCollection;

}

@Entity
@Table(name = "[b]")
public class B implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    @ContainedIn
    @JoinColumn(name = "[a_id]", referencedColumnName = "id")
    @ManyToOne(fetch = FetchType.LAZY)
    private A a;

    @IndexedEmbedded(includeEmbeddedObjectId = true, includePaths = {"id"})
    @JoinColumn(name = "[c_id]", referencedColumnName = "id")
    @ManyToOne(fetch = FetchType.LAZY)
    private C c;
}

@Entity
public class C implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;

    @Column(name = "[title]")
    private String title;

    @ContainedIn
    @OneToMany(mappedBy = "c", fetch = FetchType.LAZY)
    private Collection<B> bCollection;
}

```

TestCase

```auto
            C c1 = new C("1");
            C c2 = new C("2");
            C c3 = new C("3");

            A a = new A("1");

            Transaction tx = s.beginTransaction();
            s.persist(c1);
            s.persist(c2);
            s.persist(c3);

            s.persist(a);
            tx.commit();

            //a=> where bCollection.c.id = c1.id
            // expect false => result false
            List<A> result = searchByCId(s, c1);
            assertEquals(false, result.size() > 0);

            //Now I create new B that related to a and c1
            B b = new B(a, c1);
            Transaction tx2 = s.beginTransaction();
            s.persist(b);
            tx2.commit();

            //a=> where bCollection.c.id = c1.id
            // expect true => result false ??
            List<A> result2 = searchByCId(s, c1);
            assertEquals(true, result2.size() > 0);
            
             //rebuild the Index files!
            try {
                Search.getFullTextSession(s).createIndexer().purgeAllOnStart(true).startAndWait();
            } catch (InterruptedException e) {

            }
            
            //a=> where bCollection.c.id = c1.id
            // expect true => result true
            List<A> result3 = searchByCId(s, c1);
            assertEquals(true, result3.size() > 0);

```

---

<div class="post-metadata">

**Author:** ![Ronak\_S](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ronak_s/32/641_2.png) [@Ronak\_S](https://discourse.hibernate.org/u/Ronak_S)\
**Post date:** [August 20, 2018, 8:17am UTC](https://discourse.hibernate.org/t/index-not-updated-after-updating-indexedembedded-collections/1259/2 "2018-08-20T08:17:52Z")

</div>

Hi, Am too facing an issue resembling to your scenario. Please share your solution/fix/response on StackOverflow [SO Issue link](https://stackoverflow.com/questions/51906319/data-not-persisting-for-conatinedin-entity-on-two-way-relationship-with-index)
