我在数据库中有一个查询,其中我传递了带有联接和实体图的规范,这会产生额外的联接,并且我得到了双左联接
EntityGraph(
type = EntityGraphType.LOAD,
attributePaths = {
"investorProfile",
"investorProfile.investorProfileQuestionaries",
"assetsRatio",
"accountFees",
"netAssetValues",
"note",
"clientAppropriateness"
})
Page<ClientView> findAllBySpecificationWithPage(Specification<ClientView> specification,
Pageable pageable);
并以这种格式获取请求
select
cv1_0.broker_id,
cv1_0.client_id,
af1_0.broker_id,
af1_0.client_id,
af1_0.id,
af1_0.management_fee,
af1_0.success_fee,
cv1_0.accounts,
cv1_0.agreements,
ar2_0.broker_id,
ar2_0.client_id,
ar2_0.created,
ar2_0.qtd_balance,
ar2_0.qtd_twr,
ar2_0.updated,
ar2_0.ytd_balance,
ar2_0.ytd_twr,
cv1_0.broker_name,
ca1_0.client_id,
ca1_0.less_complex_appropriateness,
ca1_0.less_complex_signed,
ca1_0.more_complex_appropriateness,
ca1_0.more_complex_signed,
cv1_0.countries,
cv1_0.current_var,
ip1_0.id,
ipq1_0.client_id,
ipq1_0.id,
ipq1_0.cache_updated_at,
ipq1_0.filling_date_time,
ipq1_0.investment_advice_agreement,
ipq1_0.investor_profile,
ipq1_0.is_actual,
ipq1_0.is_cached,
ipq1_0.is_confirmed,
ipq1_0.template_id,
ip1_0.updated,
cv1_0.last_call_date,
cv1_0.last_recommendation_date,
cv1_0.name_en,
cv1_0.name_ru,
nav1_0.broker_id,
nav1_0.client_id,
nav1_0.id,
nav1_0.account,
nav1_0.currency,
nav1_0.type,
nav1_0.value,
nav1_0.version,
n1_0.broker_id,
n1_0.client_id,
n1_0.comment,
n1_0.created,
n1_0.last_contact,
n1_0.tags,
n1_0.updated,
n1_0.updated_by,
cv1_0.source,
cv1_0.target_var,
cv1_0.testing_results,
cv1_0.type
from
clients_view.client_view cv1_0
left join
clients_view.assets_ratio ar1_0
on ar1_0.broker_id=cv1_0.broker_id
and ar1_0.client_id=cv1_0.client_id
left join
clients_view.account_fee af1_0
on cv1_0.broker_id=af1_0.broker_id
and cv1_0.client_id=af1_0.client_id
left join
clients_view.assets_ratio ar2_0
on ar2_0.broker_id=cv1_0.broker_id
and ar2_0.client_id=cv1_0.client_id
left join
clients_view.client_appropriateness ca1_0
on ca1_0.client_id=cv1_0.client_appropriateness_client_id
left join
clients_view.investor_profile ip1_0
on ip1_0.id=cv1_0.invest_profile_id
left join
clients_view.investor_profile_questionary ipq1_0
on ip1_0.id=ipq1_0.client_id
left join
clients_view.net_asset_value nav1_0
on cv1_0.broker_id=nav1_0.broker_id
and cv1_0.client_id=nav1_0.client_id
left join
clients_view.note n1_0
on cv1_0.broker_id=n1_0.broker_id
and cv1_0.client_id=n1_0.client_id
where
(
cv1_0.broker_id, cv1_0.client_id
) in ((?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?), (?, ?))
order by
ar1_0.ytd_balance
AssetRatio 使连接两次
left join
clients_view.assets_ratio ar2_0
on ar2_0.broker_id=cv1_0.broker_id
and ar2_0.client_id=cv1_0.client_id`
left join
clients_view.assets_ratio ar1_0
on ar1_0.broker_id=cv1_0.broker_id
and ar1_0.client_id=cv1_0.client_id
如何解决这个问题并且只有1个加入。实体图和规范的存在是强制性的,因为我有自定义查询,带有 exsist 的选项不合适
曾经面临过同样的问题。通过将 Spring Boot 依赖项更新为 3.2.3 版本及其嵌套的 Hibernate 6.4.4
来修复此问题