简体   繁体   English

JPA / JPQL返回不完整的结果,其中xy IS NULL或xyz = 1

[英]JPA/JPQL returns incomplete results with WHERE x.y IS NULL OR x.y.z = 1

I have the following SQL returning 13 results 我有以下SQL返回13个结果

SELECT *
FROM AAA a
JOIN BBB b ON b.id = a.b_id
LEFT JOIN CCC c ON c.id = b.c_id
LEFT JOIN DDD d ON d.id = c.d_id
WHERE b.c_id IS NULL
OR d.status = 1

And following JPQL returning 3 results 然后JPQL返回3个结果

SELECT a
FROM AAA a
WHERE a.b.c IS NULL

And following JPQL returning 10 results 然后JPQL返回10个结果

SELECT a
FROM AAA a
WHERE a.b.c.d.status = 1

But the following JPQL returns 10 results, missing the 3 null ones. 但是以下JPQL返回10个结果,但缺少3个空结果。

SELECT a
FROM AAA a
WHERE a.b.c IS NULL
OR a.b.c.d.status = 1

What am I missing? 我想念什么? Where do I begin debugging this? 我从哪里开始调试呢?

Where do I begin debugging this? 我从哪里开始调试呢?

If you're uncertain about your ORM, tune the log level so you could see the generated SQL queries or directly check database logs. 如果不确定ORM,请调整日志级别,以便可以查看生成的SQL查询或直接检查数据库日志。

What am I missing? 我想念什么?

Condition WHERE abcdstatus = 1 forces jpa provider to create inner joins for all tables in the path (BBB, CCC, DDD). 条件WHERE abcdstatus = 1强制jpa provider为路径中的所有表(BBB,CCC,DDD)创建内部联接。 This neutralizes OR condition abc IS NULL . 这消除了OR条件abc IS NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM