org.springframework.dao.DataIntegrityViolationException - spring

while adding some data to table from jsp, only one row of data gets inserted
Also an org.springframework.dao.DataIntegrityViolationException is thrown.
Can you say why this exception is raised?

The exception is in most cases about database constraint violation. - In your case I would guess it is some unique constraint - but this is only guessing.

Related

How to recognize what constraint cause an exception in an insertion in Sqlite

How could I know what type of constraint exception is raised in an insertion in Sqlite. What it caused?. For example if I design a table with an unique constraint and primary key constraint, and I insert a row that violate a constraint, sqlite will raise an SqliteConstraintException, but I would like to know which of both constraints was violated. That would be helpful for creating an error message for the user. Instead of writing functions that validate the row before inserting it. Thank you for your help.
That information is not provided as a field on the Exception. You can use the getMessage() method to get some information about the cause. Like UNIQUE constraint failed: event.id as an example. This is telling you the name and the column which violated the constraint, but not the name of the constraint which is violated.

How to retrieve the row that caused exception using spring framework's namedParameterJdbcTemplate

I am inserting user information where a few columns have unique constraint on them one of which is email id. In testing when I try to insert the same user twice I get the
org.springframework.dao.DuplicateKeyException
it also does tell me which column violated the unique constraint but it does not give me back the row that triggered the violation. I have seen solution where the user has caught such exception and run a query based on column on which violation was triggered but does spring have anything that will return the row details along with the exception.
I tried looking but there is so much information explaining why the exception happened that I do not find a solution that returns the row that caused the violation.

Oracle deadlock output when caused by foreign keys

We have a multi-threaded batch job ending up in deadlock. I am getting conflicting answers from our dba's as to what actually causes the deadlock.
Caused by: java.sql.SQLException: ORA-00060: deadlock detected while waiting for resource
The error output references the sql for inserting into table A. Every row going into table A should be unique. Table A has foreign keys on two other tables, both of which are indexed and primary keys made up of two columns. Many rows in Table A can point to the same FK in the parent tables. Our code handles FK errors by trying to insert into parent tables and then trying into Table A again.
The sql in the trace log refers to the Table A insert sql (does not show param binding values). Does this mean definitively that there are two identical sql statements trying to be inserted into Table A in which case our prior logic is not thread-safe somewhere? Or could it really be that there are two inserts both referencing an unsatisfied FK? And the deadlock occurs from our error handling in trying to insert into the parent table. If so, would the sql in the trace not then reference the parent table sql?
Or perversely, does the original insert attempt put a lock on the row and then after handling the error, does the second attempt of the insert cause the deadlock? Any further debugging assistance?
There's not much info to work with, but my guess would be that two threads are trying to insert the same rows into one of the 'two other tables' at the same time. Idea on debugging below
Use a trigger on table A and on the other two tables ( 3 triggers in total) that write the inserted data to logging tables in an autonomous transaction that commits. This way you can see the uncommitted inserts that were rolled back due to the deadlock (the rows that exists in the logging tables but not in the actual tables are the ones that were rolled back).
HTH, KR

Codeigniter ORA-00001: unique constraint

This error: Message: oci_execute (): ORA-00001: unique constraint (SCHEMA_NAME.NAME CONSTRAINT) violated
I wonder if I do not how to handle the error more simply, more generic.
Because otherwise I will have to work on each function of the models to check the data before adding, for no duplications and not give the error noted above.
Does anyone know a simple way to solve this?
Thanks.
There is a hint that can be specified that will allow the statement to succeed without inserting the duplicated data. It can be useful for replication or bulk data loading where the job may attempt to insert the same data multiple times. I wouldn't recommend it as part of a user application.
"The IGNORE_ROW_ON_DUPKEY_INDEX hint applies only to single-table INSERT operations. It is not supported for UPDATE, DELETE, MERGE, or multitable insert operations. IGNORE_ROW_ON_DUPKEY_INDEX causes the statement to ignore a unique key violation for a specified set of columns or for a specified index. When a unique key violation is encountered, a row-level rollback occurs and execution resumes with the next input row."

Oracle BPEL DB Adapter constraint exception when writing in two tables - suddenly broken

I've got a Oracle BPEL process running on WebLogic which is writing in two tables using Database Adapters.
There are two tables, TableA and TableB. TableB has a foreign key to TableA.
I the process I create an entry in TableA with A_ID. When I create an entry in TableB using A_ID as a FK I get a constraint exception.
What is weird, this worked last week and now, using the same data, I get the error.
The datasource is set up as a standard - non-XA datasource.
This is the exception that is thrown:
<env:Fault>
<faultcode>env:Server</faultcode>
<faultstring>Exception occured when binding was invoked.
Exception occured during invocation of JCA binding: "JCA Binding execute of
Reference operation 'insert' failed due to: DBWriteInteractionSpec Execute
Failed Exception.
insert failed. Descriptor name: [Datawarehouse.TableB].
Caused by java.sql.BatchUpdateException: ORA-02291: integrity constraint
(DWH.TABLE_A_FK) violated - parent key not found
.
".
The invoked JCA adapter raised a resource exception.
Please examine the above error message carefully to determine a resolution.
</faultstring>
<faultactor/>
<detail>
<exception>ORA-02291: integrity constraint (DWH.TABLE_A_FK) violated - parent key not found</exception>
</detail>
</env:Fault>
This has nothing to do with Oracle BPEL. For some reason, either the insert onto Table A is not successful or the insert on to Table A is not visible to Table B (second insert being in a different transaction).

Resources