Skip to content

CyclicPropertyReferenceException: Found cycle for field... [DATAMONGO-1255] #2173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
spring-projects-issues opened this issue Jul 16, 2015 · 1 comment
Assignees
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug

Comments

@spring-projects-issues
Copy link

Bilguun Bayarmagnai opened DATAMONGO-1255 and commented

Two types of scenarios are printing CyclicPropertyReferenceException log in our application similiar to the https://jira.spring.io/browse/DATAMONGO-962.
We have created tiny demo app using spring boot to illustrate these scenarios.

  1. When domain class contains itself(I guess in this case exception makes sense because there's a cycle, but if we can just ignore that.):
@Document
public class Foo {
	@Id
	private String id;
	private Bar bar;
}

public class Bar {
	private Bar previous;
}
  1. Next case is tricky. If property class(Partner) contains same field on same name(job) it throws exception. Plus Job class has to have a non-primitive field(Salary) to throw this exception.
@Document
public class Worker {
	@Id
	private String id;
	private Job job;
	private Partner partner;
}

public class Partner {
	private Job job;
}

public class Job {
	private Salary salary;
}

I'm not sure if the case #1 is intentional, but we will keep the structure as it is. But it would be great if this just a bug and can be fixed, or at least there's a way to ignore it. Case #2 can be avoided by naming differently, but still not an ideal solution.

p.s this is not causing serious issues, other than showering our console with ugly exceptions


Affects: 1.6.3 (Evans SR3)

Reference URL: https://github.com/Migakun/demo-mongo/tree/master/demo-mongo

1 votes, 4 watchers

@spring-projects-issues spring-projects-issues added type: bug A general bug in: mapping Mapping and conversion infrastructure labels Dec 30, 2020
@bjornharvold
Copy link
Contributor

This ticket has been open for a while 😆

I just experienced the same when starting to use MonetaryAmount in my documents. I see this in my log:

2023-05-25T10:34:00.686+07:00  INFO 60310 --- [           main] m.c.i.MongoPersistentEntityIndexResolver : Found cycle for field 'amountType' in type 'MonetaryAmountFactory' for path 'factory -> amount -> factory'
2023-05-25T10:34:00.688+07:00  INFO 60310 --- [           main] m.c.i.MongoPersistentEntityIndexResolver : Found cycle for field 'factory' in type 'MonetaryAmount' for path 'factory -> amount -> factory'

when I create MongoDb indexes in my reactive code:

private void indexMongoDocuments(MongoMappingContext ctx, ReactiveMongoOperations template) {
        for (MongoPersistentEntity<?> persistentEntity : ctx.getPersistentEntities()) {

            Class<?> clazz = persistentEntity.getType();
            if (clazz.isAnnotationPresent(Document.class)) {
                if (log.isDebugEnabled()) {
                    log.debug("Indexing MongoDb document: {}", clazz.getCanonicalName());
                }

                ReactiveIndexOperations indexOps = template.indexOps(clazz);
                IndexResolver resolver = new MongoPersistentEntityIndexResolver(ctx);
                final Iterable<? extends IndexDefinition> indexDefinitions = resolver.resolveIndexFor(clazz);

                Flux.fromIterable(indexDefinitions)
                        .doOnEach(indexDef -> {
                            if (indexDef.get() != null && log.isDebugEnabled()) {
                                log.debug("Creating index with name: {}", indexDef.get());
                            }
                        })
                        .flatMap(indexOps::ensureIndex)
                        .doOnError(ex -> log.warn("Ignoring: Failed to index class: {}. Reason: {}", clazz.getCanonicalName(), ex.getMessage(), ex))
                        .collectList()
                        .block();
            }
        }
    }

My questions are:

  • Why is it an INFO log message?
  • Will something go wrong when trying to persist?
  • How to avoid this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants