【发布时间】:2021-01-18 11:21:53
【问题描述】:
我的实体类如下,
Account
accountId
balance
withdrawls
deposits
@OneToMany
List<CustomerAccount> customerAccounts
CustomerAccount
accountId
customerId
accountType
customerType (Primary/Secondary)
@OneToOne
Customer customer
Customer
accountId
customerId
firstName
lastName
假设用户搜索 名字 = viki 和 姓氏 = 黑色
帐户存储库
findByCustomerAccountsCustomerFirstNameAndCustomerAccountsCustomerLastame(String firstName, String lastName);
此查询同时返回主要和次要对象,即使其中一个正在匹配。当名字和姓氏与主要匹配时,我不想返回次要。次要应为空,主要应有响应。
但它返回主要和次要。 spring jpa数据有没有办法只返回 匹配的子实体连同父实体??
"CustAccnt":{
"Account":{
"balance":"",
"deposits":""
},
"primary":{
"firstName":"Viki",
"lastName":"Black"
},
"secondary":{
"firstName":"Noah",
"lastName":"Morgan"
}
}
]}
【问题讨论】:
标签: java spring hibernate jpa entity