Skip to main content
elizabethr3160
July 19, 2023
Question

Deleting more than 1 row from a DB table.

  • July 19, 2023
  • 7 replies
  • 0 views

Hi all, 

My problem is that I am trying to delete multiple rows from a DB table at once. All the rows I'm trying to delete have the same PK as the PK is a FK from another table. This is the code I thought would work but didn't:

  • = {
         a!forEach(
              items: pv!CTI_mnthlyrevene_cntrctmnths,
              expression: a!entityDataIdentifiers(
                   entity: cons!CTI_ENTITY_MRCM,
                   identifiers: fv!item.ctmnthlyrvCntrctmnthRcrdd
              )
         )
    }

I've tried not using the foreach and it still gives me the exact same error: 

  • An error occurred while trying to delete data. No data was deleted. Details: javax.persistence.PersistenceException: org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 4; expected: 1 [entity name=CTI_mnthlyrevene_cntrctmnths, id=353]

Does anyone have a suggestion on what I should do? I need to delete multiple rows at once from the same table that have the same PK. Please let me know if this is even possible. 

7 replies

stefanhelzle0001
Brainy
July 19, 2023

In my understanding, the nature of a primary key is that it is unique, and there is only a single row for one key ever.

How do you use that code snippet?

elizabethr3160
July 19, 2023

My apologies, it's a composite key table. So 2 columns make up the PK but the second key isn't the concern. I need everything that matches the first key to be deleted as it's referencing the parent object I'm trying to delete.

stefanhelzle0001
Brainy
July 19, 2023

First, I would try to simplify that code to

a!entityDataIdentifiers(
  entity: cons!CTI_ENTITY_MRCM,
  identifiers: pv!CTI_mnthlyrevene_cntrctmnths.ctmnthlyrvCntrctmnthRcrdd
)

Then, I am interested in the output.