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
Yes, DataNucleus JPA allows it, as well as to many other databases. You make compromises by using the JPA API for other types of datastores, but it makes it easy to investigate them.
It's Easy to Connect MongoDB Atlas with Spring Boot Starter data MongoDB artifactid (the dependency we added while creating the Spring Initializr project) in pom. xml. A property on application. properties file to specify the connection string to a MongoDB cluster.
MongoRepository extends the PagingAndSortingRepository and QueryByExampleExecutor interfaces that further extend the CrudRepository interface. MongoRepository provides all the necessary methods which help to create a CRUD application and it also supports the custom derived query methods.
Spring Data for MongoDB is part of the umbrella Spring Data project which aims to provide a familiar and consistent Spring-based programming model for new datastores while retaining store-specific features and capabilities.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With