user3360162
user3360162

Reputation:

Hibernate HQL delete query

Im looking for information but I didnt find how.

I have two tables:

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

- Proveedores 

|codigo_proveedor|  mail         |
----------------------------------
|    EST        | [email protected]  |
|    ASM        | [email protected] |  
|    DAM        | [email protected] |

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!

Upvotes: 0

Views: 1952

Answers (2)

Behnam Safari
Behnam Safari

Reputation: 3071

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!

Upvotes: 0

Elbek
Elbek

Reputation: 3484

How about this?

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

Upvotes: 1

Related Questions