gpt4 book ai didi

java - JPQL - (JPA) ORA-00920 : invalid relational operator

转载 作者:行者123 更新时间:2023-12-01 08:49:18 25 4
gpt4 key购买 nike

List<InvTrnTransactionHeader> list = em.createQuery("SELECT p FROM InvTrnTransactionHeader p WHERE p.warehouse.warehouseCode IN :warehouseCode And (p.issueToWarehouseId IN :issuedWhId OR :issuedWhId is null ) And ( p.invTrnTransactionHeaderPK.transactionId IN :transactionCode OR :transactionCode is null ) And (p.vendorId IN :vendorId OR :vendorId is null) And p.invTrnTransactionHeaderPK.transactionDocumentDate >=:fromDate And p.invTrnTransactionHeaderPK.transactionDocumentDate <=:toDate And (p.invTrnTransactionHeaderPK.transactionDocumentNumber >=:fromDocument  OR :fromDocument is null) And (p.invTrnTransactionHeaderPK.transactionDocumentNumber <=:toDocument  OR :toDocument is null) And (p.vendorInvoiceNumber >=:fromInvoice  OR :fromInvoice is null) And (p.vendorInvoiceNumber <=:toInvoice  OR :toInvoice is null)")
.setParameter("warehouseCode", warehouseCode)
.setParameter("issuedWhId", issuedWhId)
.setParameter("transactionCode", transactionId)
.setParameter("vendorId", vendorId)
.setParameter("fromDate", fromDate)
.setParameter("toDate", toDate)
.setParameter("fromDocument", fromDocument)
.setParameter("toDocument", toDocument)
.setParameter("fromInvoice", fromInvoiceNum)
.setParameter("toInvoice", toInvoiceNum)
.getResultList();

如果是 null 情况,则查询工作...否则何时填充所有列表参数,查询不起作用...有任何帮助吗?

最佳答案

你的问题是当你使用时

WHERE p.warehouse.warehouseCode IN:warehouseCode

任何IN运算符,那么如果变量warehouseCode为空,JPA会将SQL转换为不带元素的IN(),并且是错误的SQL结构。

要修复此问题,您需要确保属性 warehouseCode 以及您在 IN 条件中使用的所有其他属性不为空

更新:

另请查看此链接 Prepared statement IN clause您需要使用 setArray() 方法代替 setParameter() 并使用数组

关于java - JPQL - (JPA) ORA-00920 : invalid relational operator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42482549/

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