-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@JoinFetch 遇上 @ElementCollection 時,會 join 太多次 #52
Labels
status: declined
A suggestion or change that we don't feel we should currently apply
Comments
jackjieru
added
the
status: declined
A suggestion or change that we don't feel we should currently apply
label
Dec 5, 2022
shihyuho
added a commit
that referenced
this issue
Dec 9, 2022
@jackjieru 沒辦法還原耶, 請看一下測試程式是否需調整 照你留的範例, 我基本上複製過去微調了一些命名, 跑出來看起來是正常的 select distinct ...
from customer customer0_
left outer join phones phones1_ on customer0_.id=phones1_.cust_id
where customer0_.name=? |
找到原因了,JoinFetch 次數 等同 Criteria class 的 field 數量。 |
其實這個 BUG 不只在 例如 azalea-security-sc 的 RoleEntity 有 authorities 關聯 @ManyToMany(cascade = {
CascadeType.PERSIST,
CascadeType.MERGE,
CascadeType.DETACH,
CascadeType.REFRESH
}, fetch = FetchType.EAGER)
@JoinTable(name = "ROLE_AUTH_MAPPING", joinColumns = {
@JoinColumn(name = "ROLE_ID", nullable = false)
}, inverseJoinColumns = {
@JoinColumn(name = "AUTH_ID", nullable = false)
})
Set<AuthorityEntity> authorities = new HashSet<>(); 我寫了兩個 criteria: @Data
public class RoleCriteria {
.......... RoleJoinCriteria 有 @JoinFetch(paths = "authorities")
public record RoleJoinCriteria(@NestedSpec RoleCriteria roleCriteria) {
} 因為 RoleJoinCriteria 只有一個欄位 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用的專案:azalea-tl-sc
Entity: TlMainPolicyEntity
Criteria: TlMainPolicyCriteria
方法:
Page<T> QueryBySpecExecutor.findBySpec(@Nullable Object spec, @NonNull Pageable pageable)
產生的 SQL join 了 14 次:
(DB 是 SQL Server)
不只是 join 多次,連分頁查詢的 where 條件
offset 0 rows fetch next ? rows only
都沒出現如果 criteria 拿掉
@JoinFetch
,則有正常出現The text was updated successfully, but these errors were encountered: