@Document(collection = "ROOT_ENTITY")
/* * Workaround to fix the issue: just swap this.b and this.c here in this class :) */publicBb;
Class B is not highly interesting, the only note is it must include some fields not of simple types, for example D (the contents of D doesn’t matter):
Class C also includes B (it is crucial that B is included both in A and C):
When the application with such a class structure boots, it gives a false warning: org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$CyclicPropertyReferenceException: Found cycle for field 'd' in type 'B' for path 'b' which was probably intended to fix such cases but still fails under some rare conditions.
Source of the problem
When MongoPersistentEntityIndexResolver searches for the cycles, it records the possible inclusion paths as a set of the strings, and then tries to match the current stringified path with the previously found paths. In this example ".b" is found to be a substring of "c.b", so it gives a false positive warning.
Note that C must include some non-simple fields (class D in the example), otherwise it would be outfiltered by the conditional logic in org.springframework.data.mapping.model.AbstractPersistentProperty.getTypeInformationIfEntityCandidate.
Simply swap the lines public B b; and public C c; in the definition of the class A. In this case, traverse order changes, and the cycle detector will try to check whether "c.b" is a substring of ".b", which is not, and no warning will be issued :)