gpt4 book ai didi

mysql - Hibernate delete with joins with joins without using IN 不使用 IN

转载 作者:行者123 更新时间:2023-11-30 23:14:48 25 4
gpt4 key购买 nike

我有以下有效的查询,但它太慢了,因为它正在使用 IN:

_session.CreateQuery(@"
delete OrderItem oi
where oi in
(select i
from OrderItem i
where i.Product.Id = :productId
and i.Order.Company.Id = :companyId
and i.Order.Campaign.Id :campaignId
and i.Order.OrderStatus = :orderStatus)
")
.SetParameter("productId", productId)
.SetParameter("companyId", companyId)
.SetParameter("campaignId", campaignId)
.SetParameter("orderStatus", orderStatus)
.ExecuteUpdate();

有没有一种方法可以使用 native 查询,您可以简单地使用连接进行删除,例如:

DELETE posts
FROM posts
INNER JOIN projects ON projects.project_id = posts.project_id
WHERE projects.client_id = :client_id

最佳答案

是的。使用 Session.createSQLQuery()并且您可以使用纯 SQL。

关于mysql - Hibernate delete with joins with joins without using IN 不使用 IN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18413282/

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