使用连接删除Hibernate而不使用IN

时间:2013-08-23 23:26:06

标签: mysql sql hibernate

我有以下查询可行但速度太慢,因为它使用的是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();

有没有办法使用本机查询,您只需使用连接进行删除,如:

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

1 个答案:

答案 0 :(得分:0)

是。使用Session.createSQLQuery(),您可以使用纯SQL。