简体   繁体   中英

Hibernate HQL delete query

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!

How about this?

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM