Posts tagged ‘database’

Debugging oracle constraints

On more than one occasion I have been stumped with a message like this.

java.sql.BatchUpdateException: ORA-00001: unique constraint (SYSTEM.SYS_C0089989) violated

Apart from blaming oracle for being lazy and not putting the table/column name in the error message - there is nothing else that comes to mind when I see something like this.

Finding out the table and the constraint - you can connect to plsql and execute this query:

select constraint_name, constraint_type, table_name from user_constraints where constraint_name like 'SYS_C0089989';

The result is something like this:

"CONSTRAINT_NAME","CONSTRAINT_TYPE","TABLE_NAME"
"SYS_C0089989","P","JOBAUDIT"

This information gives you the table name and the constraint type on that table.

Here is what the constraint type columns mean:

C   Check on a table                Column
O   Read Only on a view           Object
P   Primary Key                       Object
R   Referential AKA Foreign Key  Column
U   Unique Key                        Column
V   Check Option on a view       Object

So looking back I know my code is trying to insert a duplicate id in the table.