jparepository custom @query生成不需要的十字架加入

发布于 2025-01-20 03:08:53 字数 1033 浏览 0 评论 0原文

帐户实体代码:

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    @NotFound(action = NotFoundAction.IGNORE)
    private User user;

用户实体代码:

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
    private List<Account> account = new ArrayList<>();

存储库自定义方法查询注释

@Query(value = "FROM Account a WHERE (:userId IS NULL Or a.user.id = :userId))

它生成此查询:

from account account0_ cross join user user1_ where account0_.user_id=user1_.id and (? is null or user1_.id=?) 

在我将 springboot 从 2.1.4.release 更新到 2.6.5 之前工作正常,

预计如下:

from account account0_ WHERE (:userId IS NULL Or account0_.user_id = :userId)

不知道是否是由于版本变化与否。

有人可以提供一些线索吗?

account entity code:

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    @NotFound(action = NotFoundAction.IGNORE)
    private User user;

user entity code:

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
    private List<Account> account = new ArrayList<>();

the repository cusotom method query annotion

@Query(value = "FROM Account a WHERE (:userId IS NULL Or a.user.id = :userId))

It generates this query:

from account account0_ cross join user user1_ where account0_.user_id=user1_.id and (? is null or user1_.id=?) 

It worked fine before I updating springboot from 2.1.4.release to 2.6.5

which is expected to be the following:

from account account0_ WHERE (:userId IS NULL Or account0_.user_id = :userId)

Don't know if it's due to the version change or not.

Can someone give some clues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗喜 2025-01-27 03:08:53

这是JPA上的疾病行为

 @NotFound(action = NotFoundAction.IGNORE)

如果您使用以上宣言, ,
删除这将是正常行为。

It's a stange behavior on JPA if you use

 @NotFound(action = NotFoundAction.IGNORE)

this above annotion,
remove this will behave normally.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文