Open MKaramavrov opened 3 months ago
In our project, we faced the same issue with lazy mapping of the entities during runtime. Version, which we currently use is 2.4.11.
I'm hesitant to do too much thread-safety work here as this is a very common method to call. A better fix, on your end, is to not rely on lazy mapping (especially as that is going away) and explicitly map your classes/packages up front. This should eliminate your issues. Please try pre-mapping and see if your issue goes away. If it doesn't, we can talk about this PR.
That was already a discussion here: https://github.com/MorphiaOrg/morphia/discussions/2802 Would be nice to have a fix at least for 2.4.x version, because we've just migrated from version 1.6.x to 2.4.11 and we are currently trying to preregister every entity on startup, but there is conceptual issue, because morphia does not enforce preregistration and during code change someone can miss some entity which will lead to hard to catch and reproduce issue.
@evanchooly Could we please consider fixing the issue at least for 2.4.x versions? Not sure that we will have too much thread safety, as we are checking for presence of existing model before making it synchronized:
if (existing != null) {
return existing;
}
Discussed in https://github.com/MorphiaOrg/morphia/discussions/2802