Click here to Skip to main content
15,667,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a table in DB as below.It accessing through JAVA(JPA)

I have a table in DB as below.It accessing through JAVA(JPA)

ID  | Name  | Parent_id
1   | Ann   | NULL
2   | Mary  | 1
3   | John  | 2
4   | Joshep| 2
5   | Peter | NULL
6   | Jeni  |5

Here Parent id refers ID of same table. if I remove any data ,all the decedents data all also will be removed.(Used ON CASCADE DELETE). For example if Name -Ann,ID-1 is removed, IDs 2,3,4 also getting removed. ON CASCADE DELETE doesn't count rows affected implicitly. Appreciate if you could anyone suggest the way to count the affected rows?

mysql hibernate jpa sql-delete cascade

What I have tried:

Query query=entityManager.createQuery("DELETE FROM Table e WHERE = :id ");
                           query.setParameter("id", 1);
           int count=query.executeUpdate();

here count always remains 1, even it removed reference records as well!
Updated 15-Sep-20 14:22pm

1 solution

This is what MS says about it:
This executeUpdate method is specified by the executeUpdate method in the java.sql.Statement interface.

If executing a stored procedure results in an update count that is greater than one, or that generates more than one result set, use the execute method to execute the stored procedure.

I don't know what the sum of your components amounts to.

executeUpdate Method (java.lang.String) (SQLServerStatement) - SQL Server | Microsoft Docs[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900