Index not updated after updating IndexedEmbedded collections

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

@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

            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);
1 Like

Hi, Am too facing an issue resembling to your scenario. Please share your solution/fix/response on StackOverflow SO Issue link