我使用以下方法分析了 JPA 代码:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
and hibernate-core 5.4.12.Final
当我编码时:
predicates.add(
cb.or(
cb.notEqual(depotJoin.get(Depot_.codeWorkflow), ChoixCodeWorkflowDepot.E1_A_CONSTITUE),
cb.or(
cb.isFalse(cb.isNotNull(depotJoin.get(Depot_.vente))),
cb.isFalse(cb.isNotNull(depotJoin.get(Depot_.dac))),
cb.isFalse(cb.isNotNull(depotJoin.get(Depot_.courrier))),
cb.isFalse(cb.isNotNull(depotJoin.get(Depot_.demandeCjn))),
cb.isFalse(cb.isNotNull(depotJoin.get(Depot_.demandeFcddv)))
)
)
);
它在 mySql 中被翻译成这样:
AND (
depot7_.code_workflow <> 'E1_A_CONSTITUE'
OR depot7_.vente_fk IS NOT NULL
OR depot7_.dac_fk IS NOT NULL
OR depot7_.courrier_fk IS NOT NULL
OR depot7_.demande_cjn_fk IS NOT NULL
OR depot7_.id IS NOT NULL
)
为什么下面的谓词存在?:
OR depot7_.id IS NOT NULL
它使该子句始终为真,从而导致不应检索的结果中出现错误。
此外,是否翻译:
cb.isFalse(cb.isNotNull(depotJoin.get(Depot_.vente))),
正在工作中 ?因为 isNotNull 被翻译为“myfield IS NOT NULL”但使用 isFalse,它应该翻译为最终“myfield IS NULL”
你怎么看呢 ?
谢谢,周末愉快。