开发者

How to include NULL using Order By with JPQL?

开发者 https://www.devze.com 2023-04-12 23:41 出处:网络
I am trying to run such JPQL query: SELECT t1 FROM Table1 t1 ORDER BY t1.column1.id ASC Column1 as such implementation:

I am trying to run such JPQL query:

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

Column1 as such implementation:

// bi-directional many-to-one association to Table1
@ManyToOne(fetch = FetchType.LAZY)
@Joi开发者_StackOverflow社区nColumn(name = "idTable1Parent")
private table1      column1;

Table1 column idTable1Parent is a FK to the Table1 column id PK.

Some records have idTable1Parent as NULL.

The problem is when I ORDER BY ASC the values, the records that have idTable1Parent are not returned, and I need that records.

Do you have some tips or solution so I can get the records that have idTable1Parent as null?

Thanks in advance.


You need to use an outer join,

SELECT t1 FROM Table1 t1 left join t1.column1 c1 ORDER BY c1.id ASC

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号