【发布时间】:2020-08-28 20:17:40
【问题描述】:
我正在使用 JPA,并且我使用了 @Query 连接两个表,现在我的要求是我可以在 where 条件下组合可能的值,有些可能为 null 或空。
我的@Query 包含(value = "Select * From A a Left Outer Join B b On A.Id=B.Id where :fromDate is NULL and :toDate is NULL or B.Activity_Date_Time Between :fromDate AND :toDate")**
我在查询中处理这个问题,它对 String 工作正常,但对于 TIMESTAMP 却给出错误,因为
嵌套异常是 org.hibernate.exception.SQLGrammarException: could 不提取 ResultSet] 的根本原因 java.sql.SQLSyntaxErrorException:ORA-00932:不一致的数据类型: 预期的 TIMESTAMP 得到 BINARY
我在日志中从 JPA 生成 SQL,在 SQL 开发人员上运行良好
Select
*
From
table A
Left Outer Join
table B
On A.Id=B.Id
Where (
A.Customer = 'fsfsfsdfsfd'
)
and (
null is null
and null is null
or B.Activity_Date_Time Between null AND null
)
And (
'MATURITY' is null
or B.Activity_Type = 'MATURITY'
);
【问题讨论】:
-
请向我们展示您正在使用的完整方法和生成的SQL。请将两者都格式化为源代码。
标签: hibernate jpa spring-data-jpa