JPQL - (JPA)ORA-00920:无效的关系运算符

时间:2017-02-27 09:53:13

标签: java jpa jpql java-ee-7

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();

查询工作是否为空案例...否则什么时候填写所有列表参数查询无效...任何帮助?

1 个答案:

答案 0 :(得分:1)

你的问题出在你使用时

WHERE p.warehouse.warehouseCode IN:warehouseCode

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

要修复它,您需要确保属性 warehouseCode ,并且您在IN条件下使用的所有其他属性都不为空

<强>更新

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