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

Error: Caused by: dev.morphia.query.ValidationException: Could not resolve path 'customParams.inventory.data' against <SOME_ENTITY_CLASS>. Unknown path element: 'data'. #2253

Closed
Hussain-Badshah opened this issue Feb 14, 2023 · 6 comments
Labels
Milestone

Comments

@Hussain-Badshah
Copy link

Hi all, I have morphia 2.2.3 version in my project and here's what the scenario is:

I have a map of map field in my @entity class like following: Map<String,Map<String,String>> map; and I am trying to update the value of inner map's key, for example let's assume that in the existing document, map looks like following:

map
{
"inventory"
{
"data":"123"
}
}

then I want to update the value against "data" key in the inner map "inventory" to let's say "456". Now, to update, below is the couple of lines of code I have in my project:
Bson bsonUpdates = com.mongodb.client.model.Updates.combine(q.update(updateOperations).toDocument(), com.mongodb.client.model.Updates.set(LAST_UPDATED_TIME, LocalDateTime.now()));
UpdateResult ur = mongoCollection.updateMany(q.toDocument(), bsonUpdates, new UpdateOptions().multi(true).upsert(false));

From the first line above, from one of the nested calls from toDocument() method, from PathTarget#resolve() method following exception is getting thrown: Error: Caused by: dev.morphia.query.ValidationException: Could not resolve path 'customParams.inventory.data' against 'com.harman.ignite.vehicleprofile.domain.VehicleProfile'. Unknown path element: 'data'.

In my test case the key that I am generating is "map.inventory.data" but if for the key: "map.inventory.123" or to say in general, for any such key: "map.inventory.<any_numeric_key>" the same test case is passing and the update operation is getting done successfully.

I don't understand why only for a literal String at the end of the DB key it's failing. Am I doing anything the wrong way? Could you somebody please help me with this error/exception? We are totally blocked because of this issue, any suggestion/help would be really helpful.

@Hussain-Badshah Hussain-Badshah changed the title Error: Caused by: dev.morphia.query.ValidationException: Could not resolve path 'customParams.inventory.data' against 'com.harman.ignite.vehicleprofile.domain.VehicleProfile'. Unknown path element: 'data'. Error: Caused by: dev.morphia.query.ValidationException: Could not resolve path 'customParams.inventory.data' against <SOME_ENTITY_CLASS>. Unknown path element: 'data'. Feb 14, 2023
@evanchooly
Copy link
Member

Can you share your entity and the query code?

@Hussain-Badshah
Copy link
Author

Hussain-Badshah commented Feb 20, 2023

Can you share your entity and the query code?

@evanchooly
Below is the entity class:

@Entity("ecallEvents")
public class ECallEvent extends AbstractIgniteEvent implements AuditableIgniteEntity {
    @Id
    private String ecallId;
    private long hits;
    private long dunks;
    @Property("testCounter")
    private long counter;
    private BytesBuffer bytesBuffer;
    private List<String> listAttr1 = new ArrayList<String>();
    private List<String> listAttr2 = new ArrayList<String>();
    private Set<String> setAttr1 = new HashSet<String>();
    private Set<String> setAttr2 = new HashSet<String>();
    private LocalDateTime lastUpdatedTime;
    private LocalDate localDate;
    private LocalTime localTime;
    private List<AuthUsers> authorizedUsers;
    private Map<String,Map<String,Integer>> customParams;
    private TestEntity entity;
    
    @Entity
    public static class AuthUsers {
        private String userId;
        private String role;
        private String status;
        private LocalDateTime createdOn;
        private LocalDateTime updatedOn;
    }
    
    @Override
    public String toString() {
    	return "AbstractIgniteEvent [TestEntity = "+this.entity+", version=" + version + ", timestamp=" + timestamp + ", eventData=" + eventData + ", requestId=" + requestId + ", sourceDeviceId=" + sourceDeviceId + ", vehicleId=" + vehicleId + "]";
    }
}

Below are the couple lines through which I am trying to update the customParams field in my Entity class:

   Bson bsonUpdates = com.mongodb.client.model.Updates.combine(
      q.update(updateOperations).toDocument(),
      com.mongodb.client.model.Updates.set(LAST_UPDATED_TIME, LocalDateTime.now()));
      
   UpdateResult ur = mongoCollection.updateMany(q.toDocument(), bsonUpdates, new UpdateOptions().multi(true).upsert(false));

In above lines, q's datatype is Query<ECallEvent>

Please let me know if anything else is required.

@evanchooly
Copy link
Member

OK. I think i know the problem but I'm not where I can properly test it myself. Morphia has some capability for validating a query down to a map property but apparently gets confused if you try to go multiple levels deep in to that map. Disabling validation on that query should get you around this for now and I can play with making that validation work better on Map properties.

As a side note, it's weird that you're mixing Morphia and driver features in that update. It should all be doable from purely Morphia code. It'd make your code much simpler to not mix like that.

@evanchooly evanchooly added this to the 2.4.0 milestone Feb 20, 2023
@Hussain-Badshah
Copy link
Author

@evanchooly maybe you can have a similar or the same entity class as ECallEvent in my previous comment and in it you can have a map of map type property and in your test case you can try updating only that particular field through morphia 2.2.3 or with any later version.

Another thing I would like to bring to your attention is that the exact same use case of mine was working as expected with 1.6.1 morphia version. Below is how update was being done with 1.6.1 version:

UpdateResults ur = mongoDatastore.update(q, updateOperation);

where, mongoDatastore's type is AdvancedDatastore, q's type is Query and updateOperation's type is UpdateOperations
Since the above update method was deprecated, we had to change our implementation to what I have mentioned in my previous comment.

On a different note, do you have any reference to some document that explains how to update any field in an entity class using pure morphia library code, in version 2.2.3? If you do, can you please share? I will go through it and try to incorporate the same in my project.

@Hussain-Badshah
Copy link
Author

@evanchooly as you suggested, tried updating through pure morphia code too, the below way:

UpdateResult ur = datastoreNew.find(entityClass).update(updateOperations).execute(); - Mentioned in the official morphia docs but this also resulted in the same exception. execute() internally calls a toDocument() method of UpdateBase, and there's something wrong in the flow from toDocument() onwards. After the control goes inside toDocument(), it fails with the aforementioned exception.

Below is the stack trace for your reference:

dev.morphia.query.ValidationException: Could not resolve path 'customParams.inventory.data' against '<entity.class.package.name>'. Unknown path element: 'data'.
at dev.morphia.internal.PathTarget.failValidation(PathTarget.java:137)
at dev.morphia.internal.PathTarget.resolve(PathTarget.java:166)
at dev.morphia.internal.PathTarget.getTarget(PathTarget.java:121)
at dev.morphia.query.OperationTarget.encode(OperationTarget.java:48)
at dev.morphia.query.Operations.toDocument(Operations.java:74)
at dev.morphia.query.UpdateBase.toDocument(UpdateBase.java:88)
at dev.morphia.query.Update.execute(Update.java:45)
at dev.morphia.query.Update.execute(Update.java:35)

@evanchooly
Copy link
Member

i just pushed 2.3.4 which should fix this problem for you.

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

No branches or pull requests

2 participants