-
Notifications
You must be signed in to change notification settings - Fork 31
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
Embedded collections doesn't work with gorm 7.3.0 #589
Comments
@puneetbehl The change:
NEW
OLD EDIT:@puneetbehl NEW EDIT. IMPORTANT!This is not the solution. The solution is found below, in the modification of the getValue() method |
@puneetbehl |
@puneetbehl class MongoEntityPersister FROM
TO
|
I believe I'm running into the same issue. We're also upgrading to Grails 5.3.2 (from 3.3.10) and GORM for MongoDB 7.2.1 (from 6.1.7). We're finding that when you're dealing with two levels or more of For example, given the following data structure:
If I were to do a GORM call @lucas-napse are you just running with a local fork of this repo with your changes included in your dependencies? |
@seanhastings @puneetbehl |
@lucas-napse Unfortunately it seems like the fix for your issue didn't fix mine, I'll need to keep digging. |
please, @puneetbehl , review this change. We need to have this solution in our system so that it can work without problems. Very thankful. |
I'm attempting to recreate the issue through testing with GORM MongoDB. Could you kindly generate a sample application that mimics the problem? Furthermore, I believe employing the subsequent approach would offer a superior solution: Within org/grails/datastore/mapping/mongo/engine/MongoEntityPersister.java file: dbo.getClass().isAssignableFrom(Document.class) In relation to the pull request, my understanding is that the procedure involves initially forking the repository, implementing your modifications, and subsequently initiating a new pull request from the forked repository. Please inform me if this method is ineffective for you. |
We also urgently need this fixed. If I generate a sample app for this problem, can I hope for at least a patch release relatively soon? I'm also concerned that the assumption seems wide-spread that the driver returns a Document when it actually returns a LinkedHashMap. |
+1 - we faced the same issue after upgrade |
So for us issue is also caused in MongoEntityPersister but in different place. Maybe @seanhastings you can check it for yourself too: Issue is in loadEmbeddedCollection, if embedded collection is not a map, this method will create collection and try to map instances, but it also checks only for "Document" and ignores any other values. It happens on this line:
|
But I had issue to reproduce this on fresh project and I did more debugging. The difference I found is that our migrated project did not use the codec engine. After I added What I was not able to find for now is why codec is used for freshly generated project but is not used for my legacy one. I could see if codec is used in |
Using the grails.mongodb.engine property (my fresh project had none) fixed for me. Thanks! I'm running into 2 more incompatible errors.
|
@practical-programmer forgot to get back to this here with my own solution, but I also was able to fix our problem by switching to the "codec" engine, we were on "mapping". |
Hi! @puneetbehl |
Is there any documentation on grails.mongodb.engine and differencens between codec v.s. mapping? |
@lucas-napse I think it would make sense to add this to upgrade notes under documentation. |
I had that problem, I couldn't find the solution, in my case I couldn't update embedded documents and the solution I had found was adding engine:mapping in the .yml. |
|
Hi @puneetbehl !
In our system we have a large number of domain classes. In our recent upgrade to grails 5 (5.3.2) that makes use of GORM 7.3.0 of our system, which was working fine with the Grails 2.5.6, we noticed that the embedded entities were not loaded in the object that contained it: For example,
In the above
Country
has embeddedregions
, these regions are initialized as anempty list
when loaded through GORM. Whereas, in the database collectionCountry
hasregions
. Even, when using the MongoDB API, these regions are loaded correctly as list ofDocument
.This does not work when using either
Country.findAll()
, orCountry.createCriteria().list{}
. It maybe breaking with other GORM queries as well.Upon, debugging, we noticed that the problem might be caused because the database returns a
Map
instead of aDocument
. The Groovy classMongoEntityPersister
exclusively checks for the classDocument
which breaks certain conditions. For example:MongoEntityPersister.loadEmbeddedCollection()
.When the method is executed, I noticed that in our case it goes through the
else
branch because the following condition evaluates tofalse
The above results in embedded
regions
to return an emptyList
because it is aMap
.By modifying the above to following, might fixes the problem:
The above change solves the our problem where the
regions
are correctly loaded via the GORMCountry.findAll
method.Doing more tests I notice that there is a second problem: if this embedded entity uses composition, some related attributes are loaded and others are not.
For example: my country has regions, and a region has a region type. This type of region is a Domain. The regions are embedded in the country, and a region has only one type of region, as an associated instance (composition).
This instance, the region type, is not loaded.
Performing more debugging, I find that the code goes by:
NativeEntityPersister#refreshObjectStateFromNativeEntry(PersistentEntity, Object, Serializable, T, boolean)
... continuing debugging leads to this method ...
... continuing debugging leads to this method ...
...clearly this method gives true when it is a Document, but my region type appears as Map, which gives false. This, by giving false, the caller (AbstractMongoObectEntityPersister#getEmbedded(T, String)) determines that it is null, so it does not load my region type.
Making this change should fix it:
The problem now is that internally we get various errors related to the Map and Document type. And these are related to the getValue() and setValue() methods of the MongoEntityPersister class:
This is the error you get after making all the changes I mentioned above:
As a solution we will try to use an older version of gorm, but if this problem can be solved it would be great since it is always necessary to have the latest. If you need more information, please comment and I will respond as soon as possible.
Some details:
| Grails Version: 5.3.2
| JVM Version: 11.0.16.1
| Gorm version: 7.3.0
| Windows 11, with last updates.
(build.gradle)
implementation 'org.grails.plugins:mongodb:7.3.0'
implementation "org.grails:gorm-mongodb-spring-boot:7.3.0"
The text was updated successfully, but these errors were encountered: