Skip to content
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

Enhance reference documentation and cover MongoManagedTypes #4365

Open
emoen opened this issue Apr 14, 2023 · 9 comments
Open

Enhance reference documentation and cover MongoManagedTypes #4365

emoen opened this issue Apr 14, 2023 · 9 comments
Labels
type: documentation A documentation update

Comments

@emoen
Copy link

emoen commented Apr 14, 2023

MongoManagedTypes are not mentioned in the v 4.0 release even though they where released in that version. They are needed when overriding mongoMappingContext(MongoCustomConversions customConversions, MongoManagedTypes types) which are needed for custom converters. Can you update java-doc and give an example where there is 2 or more customConverters?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 14, 2023
@christophstrobl
Copy link
Member

Thanks for pointing out the blank spot in the reference documentation.

As per the Javadoc of the ManagedTypes interface those are:

Types managed by a Spring Data implementation. Used to predefine a set of known entities that might need processing during the initialization phase.

Basically its the initial entity set now exposed as a dedicated type which helps detect them during a potential AOT phase to run inspections required when building a GraalVM native-image.

@christophstrobl christophstrobl changed the title What are MongoManagedTypes? Enhance reference documentation and cover MongoManagedTypes Apr 14, 2023
@christophstrobl christophstrobl added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 14, 2023
@emoen
Copy link
Author

emoen commented Apr 14, 2023

Yes, I found the commit where the change was done: java/org/springframework/data/mongodb/config/MongoConfigurationSupport.java

@emoen
Copy link
Author

emoen commented Apr 14, 2023

Before it was mappingContext.setInitialEntitySet(getInitialEntitySet()); and now it is mappingContext.setManagedTypes(managedTypes);
So my question is - how to I migrate with this change in mind - now that mongoMappingContext() takes a new argument as input? Related stackexchange question
https://stackoverflow.com/questions/75996137/what-are-mongomanagedtypes-new-in-spring-data-mongodb-version-4-0

@emoen
Copy link
Author

emoen commented Apr 14, 2023

Basically its the initial entity set now exposed as a dedicated type which helps detect them during a potential AOT phase to run inspections required when building a GraalVM native-image.

How can I set them?

@christophstrobl
Copy link
Member

Can you share a complete minimal sample (something that we can unzip or git clone, build, and deploy) that shows what you're trying to achieve. I seem to lack some context form the linked SO question and the error posted there.

@emoen
Copy link
Author

emoen commented Apr 17, 2023

The attached image shows the problem - in spring-data-mongodb 4.0 the method getMappingBasePackages() which is defined with @ Override is not called anymore: https://ibb.co/ZdChJbQ
The stacktrace to the left is using spring-data-mongodb 3.2 - and the stacktrace contains SecurityMongoConfig before the CGLIB spring magic, while in spring-data-mongodb 4.0- there is some CGLIB magic happening before parent classes. Is that causing overriding not to work?

Edit:
The error is that after refactoring to create MonoManagedTypes in the mongoMappingContext() - our getMappingBasePages() is not called anymore.

@christophstrobl
Copy link
Member

Why do you think getMappingBasePackages is no longer called?
MongoConfigurationSupport uses getInitialEntitySet to create the MongoManagedTypes bean out of the configured base packages. As already said, please provide a complete minimal sample that reproduces the problem. Screenshots unfortunately contain way to little information to be of value.

@emoen
Copy link
Author

emoen commented Apr 18, 2023

I know getMappingBasePackages is no longer called! I see it when debugging. The default implementation of getMappingBasePackage is called instead. And that is the reason for the error. A minimal sample would just be any implementation that overrides getMappingBasePackage.

public class FooBarMongoConfig extends AbstractFooBarMongoConfig {
....
@OverRide
protected Collection getMappingBasePackages() {
return List.of("com.foo.bar.entity");
}
}

public abstract class AbstractFooBarMongoConfig extends AbstractReactiveMongoConfiguration {
...
}

@christophstrobl
Copy link
Member

christophstrobl commented Apr 19, 2023

Then providing the sample should not be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

3 participants