How do we build the Spring JPA query and retrieve data for nested Couchbase document values? I am trying to avoid writing a native query and use the JPA method to retrieve data based on keys which are nested 2 levels.
The couchbase document value is of type
Company
Where employees is a list and tasks is a property under employee which is a List with details as an object
I would like to query multiple documents and retrieve matching records by categoryId.
Extending the Repository Interface to CouchbaseRepository passing Company and the document id. I have tried something like
// finding by Employees-->Tasks-->Details-->CategoryId
findByEmployeesTasksDetailsCategoryId(Integer id); // Does not work
but does not work
"company": "Xyc",
"employees": {
"name": "John Smith",
"age": 24,
"tasks": [
{
"id": 231,
"date": "05-13-2019"
"details": {
"categoryName": "Software",
"categoryId": 12,
"description": "Buy Software"
"location": "Plano, Texas"
"zip": 75024
}
}
},
{
"id": 789,
"date": "05-14-2019"
"details": {
"categoryName": "Hardware",
"categoryId": 17,
"description": "Buy hardware"
"location": "Irving, Texas"
"zip": 75038
}
}
},
{
"id": 456,
"date": "05-15-2019"
"details": {
"categoryName": "Hardware",
"categoryId": 17,
"description": "Buy hardware"
"location": "Plano, Texas"
"zip": 75024
}
}
]
}
I'm looking for JPA method, where I can get the details task or details by categoryId.
Expected output for categoryId 17
[
{
"categoryName": "Hardware",
"categoryId": 17,
"description": "Buy keyboard and mouse"
"location": "Irving, Texas"
"zip": 75038
},
{
"categoryName": "Hardware",
"categoryId": 17,
"description": "Buy monitor"
"location": "Plano, Texas"
"zip": 75024
}
]