sql 和 hql 中相同查询的不同结果
Differents results for the same query in sql and hql
我有一个使用 angular 和 java 制作的应用程序,我尝试从数据库中获取数据。因此,我尝试在 hql(休眠)中获取我的数据,但在 hql 和 sql 中对于相同的查询我没有相同的结果。
这是我的 sql 查询:
SELECT
co.label,
sol.material_code,
sum(sol.quantity),
sol.level
FROM sales_order so
JOIN sales_order_line sol ON so.root_so_id = sol.root_so_id
JOIN customer cu ON cu.id = so.id_customer
JOIN country co on co.id = cu.id_country
WHERE so.level = 1
AND sol.material_code in ('AR1MA010', 'VJCNS102088')
GROUP BY co.label, so.level;
这是我的 hql 查询:
select
co.label,
sol.materialCode,
sum(sol.quantity),
sol.level
from SalesOrder so
join so.salesOrderLines sol on so.rootSoId = sol.rootSoId
join so.customer cu
join cu.country co
where so.level = 1
and sol.materialCode IN ('AR1MA010', 'VJCNS102088')
group by co.label, sol.level
我尝试在控制台中 运行 这些查询。所以,我的代码没有问题,但我得到了 2 个不同的结果。
对于 sql 查询,我有:
Argentina AR1MA010 16000 2
Brazil VJCNS102088 20 1
Romania VJCNS102088 12 2
对于 hql 查询,我有:
Brazil VJCNS102088 20 1
Romania VJCNS102088 1 1
你知道为什么吗?
问题来自join so.salesOrderLines sol on so.rootSoId = sol.rootSoId
.
使用 so.salesOrderLines
,您可以使用一个条件进行连接,而使用 "on",您可以添加第二个条件。但是在 sql 中,您只有 "on" 的第二个条件。所以在 hql 中,连接有 2 个条件,而 sql.
中只有一个
我有一个使用 angular 和 java 制作的应用程序,我尝试从数据库中获取数据。因此,我尝试在 hql(休眠)中获取我的数据,但在 hql 和 sql 中对于相同的查询我没有相同的结果。
这是我的 sql 查询:
SELECT
co.label,
sol.material_code,
sum(sol.quantity),
sol.level
FROM sales_order so
JOIN sales_order_line sol ON so.root_so_id = sol.root_so_id
JOIN customer cu ON cu.id = so.id_customer
JOIN country co on co.id = cu.id_country
WHERE so.level = 1
AND sol.material_code in ('AR1MA010', 'VJCNS102088')
GROUP BY co.label, so.level;
这是我的 hql 查询:
select
co.label,
sol.materialCode,
sum(sol.quantity),
sol.level
from SalesOrder so
join so.salesOrderLines sol on so.rootSoId = sol.rootSoId
join so.customer cu
join cu.country co
where so.level = 1
and sol.materialCode IN ('AR1MA010', 'VJCNS102088')
group by co.label, sol.level
我尝试在控制台中 运行 这些查询。所以,我的代码没有问题,但我得到了 2 个不同的结果。
对于 sql 查询,我有:
Argentina AR1MA010 16000 2
Brazil VJCNS102088 20 1
Romania VJCNS102088 12 2
对于 hql 查询,我有:
Brazil VJCNS102088 20 1
Romania VJCNS102088 1 1
你知道为什么吗?
问题来自join so.salesOrderLines sol on so.rootSoId = sol.rootSoId
.
使用 so.salesOrderLines
,您可以使用一个条件进行连接,而使用 "on",您可以添加第二个条件。但是在 sql 中,您只有 "on" 的第二个条件。所以在 hql 中,连接有 2 个条件,而 sql.