gpt4 book ai didi

java - 如何在 JPQL 中使用 Order By 来包含 NULL?

转载 作者:行者123 更新时间:2023-11-30 04:58:24 25 4
gpt4 key购买 nike

我正在尝试运行这样的 JPQL 查询:

SELECT t1 FROM Table1 t1 ORDER BY t1.column1.id ASC

Column1 的实现:

// bi-directional many-to-one association to Table1
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idTable1Parent")
private table1 column1;

Table1 列 idTable1Parent 是 Table1 列 id PK 的 FK。

某些记录的 idTable1Parent 为 NULL。

问题是当我按 ASC 排序值时,具有 idTable1Parent 的记录不会返回,而我需要该记录。

您是否有一些提示或解决方案,以便我可以获取 idTable1Parent 为 null 的记录?

提前致谢。

最佳答案

您需要使用外部联接,

从 Table1 t1 中选择 t1 左连接 t1.column1 c1 ORDER BY c1.id ASC

关于java - 如何在 JPQL 中使用 Order By 来包含 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7738828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com