I have a project perfectly running with Spring Data MongoDB 1.4.2. I tried to update to 1.5.0 and I get this error during autowiring (extract) :
Caused by: org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$CyclicPropertyReferenceException: Found cycle for field 'rules' in type 'Filter' for path 'filter.rules'
at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$CycleGuard.protect(MongoPersistentEntityIndexResolver.java:370) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$2.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:144) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$2.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:138) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:294) ~[spring-data-commons-1.8.0.RELEASE.jar:na]
I have a repository "RulesDAO" simply extending "MongoRepository". It manages an entity named "Rule". This entity has some basic fields and a "Filter" field. And this Filter class contains a list of Filter (which can be empty).
@Document(collection="rules")
public class Rule {
@Id private String id;
private String name;
// other fields
private Filter filter;
}
public class Filter {
// for groups
private String condition;
private List<Filter> rules = new ArrayList<Filter>();
// for query
private String field;
private String value;
}
("rules" is not a perfect name, but it has to be named this way for MVC binding)
So the Filter.rules property is interpreted as a cycle where it isn't ! (well in my understanding of the term "cycle")
Is it a bug in the release or is there a new "flag" for this usecase ?
Thanks
For the background story, the Filter class can be either a leaf or a node of a tree used to build complex Criteria, it is builded from the JSON of a jQuery plugin of mines http://mistic100.github.io/jQuery-QueryBuilder
Your code is correct. That log message is just INFO
level to tell you that there is potential cycle reference in your code.
You could ignore that annoying message by turning logger off. In case your are using Spring Boot, add this to your application.properties
file:
logging.level.org.springframework.data.mongodb.core.index=OFF