我有一个在 Oracle 中运行良好的查询,但是org.springframework.dao.TransientDataAccessResourceException当我尝试在 HSQLDB(使用 Oracle 兼容模式)中运行相同的查询时收到一个。
这是有问题的查询:
select
Orders.id,
(select sum(decode(Orders.status, 'C', Orderlines.qty, 0))
from Orderlines where orderId = Orders.id
) as "productQuantity"
from Orders
join Orderlines on Orders.id = Orderlines.orderId
where Orders.customerId = ?
group by Orders.id, Orders.status
这是堆栈跟踪的根
Caused by: org.hsqldb.HsqlException: java.lang.NullPointerException
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.result.Result.newErrorResult(Unknown Source)
at org.hsqldb.result.Result.newErrorResult(Unknown Source)
at org.hsqldb.StatementDMQL.execute(Unknown Source)
at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 60 more
Caused by: java.lang.NullPointerException
at org.hsqldb.ExpressionColumn.getValue(Unknown Source)
at org.hsqldb.Expression.getValue(Unknown Source)
at org.hsqldb.ExpressionOp.getValue(Unknown Source)
at org.hsqldb.ExpressionAggregate.updateAggregatingValue(Unknown Source)
at org.hsqldb.QuerySpecification.buildResult(Unknown Source)
at org.hsqldb.QuerySpecification.getSingleResult(Unknown Source)
at org.hsqldb.QuerySpecification.getResult(Unknown Source)
at org.hsqldb.StatementQuery.getResult(Unknown Source)
... 63 more
如果我通过删除decode子句稍微简化查询,HSQLDB 可以处理它。
select
Orders.id,
(select sum(Orders.status)
from Orderlines where orderId = Orders.id
) as "productQuantity"
from Orders
join Orderlines on Orders.id = Orderlines.orderId
where Orders.customerId = ?
group by Orders.id, Orders.status
这是 HSQLDB 的已知限制吗?
任何想法如何解决这个问题?我正在尝试使用 HSQLDB 进行单元测试,因此修改查询并不是一个真正的选择,除非该解决方案也适用于 Oracle。
湖上湖
相关分类