Hibernate HQL delete query

喜你入骨 提交于 2019-12-25 01:55:32

问题


Im looking for information but I didnt find how.

I have two tables:

  • Remesas
|codigo_prod|  nombre   |codigo_proveedor|
-----------------------------------------
|    1001   | product1  |     EST        |
|    1002   | product2  |     ASM        |

- Proveedores 

|codigo_proveedor|  mail         |
----------------------------------
|    EST        | pro@mail.com  |
|    ASM        | pro2@mail.com |  
|    DAM        | pro3@mail.com |

I have to delete from Proveedores the row that dont have codigo_proveedor on Remesas in this case delete DAM that its not on Remesas.

Thank you!


回答1:


try this:

    Session s= HibernateUtil.getSession();
    s.beginTransaction();
    s.CreateSQLQuery("delete Proveedores where codigo_proveedor not in 
                      (select codigo_proveedor from Remesas)");
    s.getTransaction().commit();

I know it for Java!




回答2:


How about this?

    delete Proveedores pr  where pr.codigo_proveedor not in 
                      (select re.codigo_proveedor from Remesas re)


来源:https://stackoverflow.com/questions/22101895/hibernate-hql-delete-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!