- Notifications
You must be signed in to change notification settings - Fork 1.1k
DATAMONGO-1819 - Do not create PersistentEntities for simple types contributed by a converter. #513
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
Conversation
| Do you have details on the side-effect?Should we maybe move the JSR-310 converters more closely to the default converters so that would've been caught by the previous implementation of |
| Consider following code: @Document("another_collection") class Person { … } class PersonWriteConverter implements Converter<Person, Document> { … } class PersonReadConverter implements Converter<Document, Person> { … }Then you're required to call Creating a repository Moving JSR310 support back to |
e171096 to a2186a5 Compare We now check during query mapping whether a property represents a simple value or an entity to not request a PersistentEntity if not required. Previously, we relied entirely on the MappingContext to return a PersistentEntity which could also happen for types that were simple types. Fix id property name in DefaultScriptOperations as we provide a converter for NamedMongoScript.
Migrate tests to AssertJ.
a2186a5 to fa0c3fd Compare | | ||
| MongoPersistentProperty property = getProperty(); | ||
| return property == null ? null : mappingContext.getPersistentEntity(property); | ||
| return property != null && property.isEntity() ? mappingContext.getPersistentEntity(property) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should rather make the ….isEntity() check part of the implementation of getPersistentEntity(PersistentProperty). That would prevent that any other calls to that method with a property that's not an entity in the first place would trigger the addition of the type to the mapping context and the code here could even stay untouched.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing either one is rather a patch than a fix to the actual issue. There's no coherent behavior between PersistentProperty.isEntity() and AbstractMappingContext.shouldCreatePersistentEntityFor(…) as both run different checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally agree, however, I'd argue it sort of has to be that way (to support the use case you described above). What I am trying to say is, on getPersistentEntity(PersistentProperty), we know that we're in the "nested" case, so that stricter rules might apply and actually can be applied. I.e. in case of the lookup of the PersistentEntity for a PersistentProperty we can apply more strict rules before adding a previously not-known type to the MappingContext than when asking for a PersistentEntity on the MappingContext as that implicitly assumes top-level types to some degree.
I'd also it's inline with the previously implicit assumption that looking up a PersistentEntity for a property, that the latter actually is considered one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right about the relationship between a property and its reference to a top-level type. We generally want to avoid introspection of types that are considered simple ones.
Let's do it that way. I'll file a separate ticket to address the missing simple type check in shouldCreatePersistentEntityFor(…).
Use native field names for NamedMongoScript query instead of relying on metadata-based mapping as NamedMongoScript is considered a simple top-level type. Migrate tests to AssertJ. Related pull request: #513.
Use native field names for NamedMongoScript query instead of relying on metadata-based mapping as NamedMongoScript is considered a simple top-level type. Related pull request: #513.
We now check for registered simple types in
MongoMappingContext.shouldCreatePersistentEntityFor(…)to preventPersistentEntitycreation for unwanted types. Previously, we only checked againstMongoSimpleTypes.HOLDERinstead of the simple types contributed by converters.This change impacts aggregate root type use with top-level converters: These types are no longer represented with a
PersistentEntitywhich removes mapping details and these types cannot be used anymore with a repository and require a collection name if used with the Template API.Related ticket: DATAMONGO-1819.