【发布时间】:2019-10-01 01:00:21
【问题描述】:
我们如何构建 Spring JPA 查询并检索嵌套 Couchbase 文档值的数据? 我试图避免编写本机查询并使用 JPA 方法根据嵌套 2 级的键检索数据。
couchbase 文档值的类型
Company
其中employees 是一个列表,tasks 是employee 下的一个属性,这是一个以详细信息为对象的List
我想查询多个文档并按 categoryId 检索匹配记录。
将存储库接口扩展到 CouchbaseRepository 传递公司和文档 ID。 我尝试过类似
// finding by Employees-->Tasks-->Details-->CategoryId
findByEmployeesTasksDetailsCategoryId(Integer id); // 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
}
}
]
}
我正在寻找JPA方法,我可以通过categoryId获取详细任务或详细信息。
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
}
]
【问题讨论】:
标签: spring jpa spring-data-jpa couchbase n1ql