We have a table called `USER_INVOICE` where the `user_id`, `invoice_id` and `invoice_status` are inserted. The table has pk constraint.
Status of the invoice can be `ACTIVE` or `CLOSED`. An user can have just one ACTIVE invoice at any moment, but more than one CLOSED invoice.
Since there is no way of adding a unique constraint to the table, we created a temp table called `LOCK_TABLE` that creates a new lock entry before adding a new invoice and releases the entry lock after the insert of the invoice and the operations on it are done.

Lately, I saw that there are still some duplicate entries somehow added to `USER_INVOICE` for some requests that are concurrent. The user clicks on add invoice multiple times and it creates the lock, adds the active invoice, then a constraint violation on `LOCK_TABLE` is displayed with error:

```
"HHH000010: On release of batch it still contained JDBC statements"

```

and another active invoice is added afterwards.
I have not figured out how the second entry to invoice is added.