I am using inherited @Embedded
reference of ArrayList in Morphia Entity
class.
@Entity
public class First {
@Embedded private List<Second> secondClass;
private String title;
private Long id;
... getter and setter .. methods
}
@Embedded
public class Second {
@Embedded private List<Third> thirdClass;
private String titleSecond;
... getter and setter .. methods
}
@Embedded
public class Third {
private String titleThird;
private String logoUrl
... getter and setter .. methods
}
Json
{
"secondClass": [{
"thirdClass": [{
"titleThird": "Java",
"logoUrl": "http://www.artsfon.com/pic/201510//artsfon.com-72885.jpg",
}, {
"titleThird": "ios",
"logoUrl": "http://www.artsfon.com/pic//1920x1080/artsfon.com-72885.jpg",
}],
"titleSecond": "Developer"
}],
"title": "Software Developer",
"id" : 1234567890
}
Questions
1) How to remove the element with the given value of titleSecond
and id
?
2) How to remove the element with the given value of titleThird
and id
?
For first I tried the following implementation:
UpdateOperations<First> ops;
Query<First> updateQuery = datastore.createQuery(First.class).filter("id", Long.parseLong(id.trim()));
ops = datastore.createUpdateOperations(First.class).disableValidation().removeAll("secondClass.titleSecond", "Developer");
datastore.update(updateQuery, ops);
but it's throwing mapping error:
Write failed with error code 16837 and error message 'cannot use the part (secondClass of secondClass.titleSecond) to traverse the element.
How can I perform the action for question 1 and 2? Any help would be appreciable.
possibly linked question: In Morphia how can i update one embedded Object inside an ArrayList
Created records like this.
My First class. Rest of the classes are same.
Answer to the first part.
Alternate solution for first part.
Answer to the second part.