question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Database ERROR: Violation of foreign key constraint

See original GitHub issue

Current Behavior:

Dependency-Track v3.5.0 has logged the following this morning, ERROR events that I have not seen previously:

2019-07-16 10:59:05,012 [] ERROR [DataNucleus.Transaction] Operation commit failed on resource: org.datanucleus.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@104e40b7, error code UNKNOWN and transaction [DataNucleus Transaction, ID=1755161285-29056011, enlisted resources=[org.datanucleus.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@104e40b7]] : ERROR: update or delete on table "COMPONENT" violates foreign key constraint "COMPONENTMETRICS_FK1" on table "COMPONENTMETRICS"
  Detail: Key (ID)=(104) is still referenced from table "COMPONENTMETRICS".
2019-07-16 10:59:11,216 [] INFO [org.dependencytrack.tasks.MetricsUpdateTask] Executing metrics update on project: c05aa9f3-f1e0-442c-ac66-36e80261e153
2019-07-16 10:59:24,961 [] ERROR [DataNucleus.Transaction] Operation commit failed on resource: org.datanucleus.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@58a8ed4a, error code UNKNOWN and transaction [DataNucleus Transaction, ID=1755161285-29057706, enlisted resources=[org.datanucleus.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@58a8ed4a]] : ERROR: update or delete on table "COMPONENT" violates foreign key constraint "COMPONENTMETRICS_FK1" on table "COMPONENTMETRICS"
  Detail: Key (ID)=(565) is still referenced from table "COMPONENTMETRICS".
2019-07-16 11:00:08,309 [] INFO [org.dependencytrack.tasks.MetricsUpdateTask] Executing metrics update on project: 49255ded-3440-4ef1-80db-8a8ca2463856
2019-07-16 11:01:02,932 [] INFO [org.dependencytrack.tasks.MetricsUpdateTask] Executing metrics update on project: a31082b1-9c51-4fef-8a87-6ea37550212e
2019-07-16 11:01:22,065 [] ERROR [DataNucleus.Transaction] Operation commit failed on resource: org.datanucleus.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@13f04890, error code UNKNOWN and transaction [DataNucleus Transaction, ID=1755161285-29067551, enlisted resources=[org.datanucleus.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@13f04890]] : ERROR: update or delete on table "COMPONENT" violates foreign key constraint "COMPONENTMETRICS_FK1" on table "COMPONENTMETRICS"
  Detail: Key (ID)=(959) is still referenced from table "COMPONENTMETRICS".
2019-07-16 11:02:08,130 [] INFO [org.dependencytrack.tasks.MetricsUpdateTask] Executing metrics update on project: ff378c0c-80fa-4847-8a15-264568fd4acf
2019-07-16 11:02:47,519 [] ERROR [DataNucleus.Transaction] Operation commit failed on resource: org.datanucleus.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@62e2f0ee, error code UNKNOWN and transaction [DataNucleus Transaction, ID=1755161285-29074622, enlisted resources=[org.datanucleus.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@62e2f0ee]] : ERROR: update or delete on table "COMPONENT" violates foreign key constraint "COMPONENTMETRICS_FK1" on table "COMPONENTMETRICS"
  Detail: Key (ID)=(623) is still referenced from table "COMPONENTMETRICS".

The cluster of 4 ERROR events was followed by a 5th a minute or so later. The events occurred in the middle of a bunch of standard “Executing metrics update on project” events.

Steps to Reproduce:

I am not quite sure. I do know that I had earlier used the UI to delete 30-40 components that were reported as being no longer in use. (all were SNAPSHOT versions).

An hour later, I did perform a click to perform a manual metrics update on one of the projects in the above log snippet… there was no error.

Expected Behavior:

More robust process for component deletion?

Environment:

  • Dependency-Track Version: 3.5.0
  • Distribution: [ Executable WAR]
  • BOM Format & Version: CycloneDX 1.1
  • Database Server: [ PostgreSQL ]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
stevespringettcommented, Jul 16, 2019

I’m not sure. The delete procedure is extensive and covers a components metrics. Here’s the dataflow as it exists in v3.5.0.

ComponentResource:298QueryManager:774QueryManager:2007

Keep an eye on it and let me know if you’re able to replicate.

0reactions
github-actions[bot]commented, Sep 22, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Violation of foreign key constraint - Stack Overflow
1 Answer 1 ... it appears you are trying to insert a record that references 'P0003' in the Purchase table, but that table...
Read more >
Violation of constraints in relational database - GeeksforGeeks
It causes violation only if the tuple in relation 1 is deleted which is referenced by foreign key from other tuples of table...
Read more >
3 Common Foreign Key Mistakes (And How to Avoid Them)
1. Mismatched data types ... When you're using a foreign key to reference a column in another table, the datatypes of both tables...
Read more >
Foreign key violation when trying to insert into a table [closed]
I am trying to insert value 15 to ID of A but a FK violation occurs. error is similar to given below: ERROR...
Read more >
Foreign key constraint violation when loading or deleting data ...
Foreign key constraint violation when loading or deleting data in database. When the destination is a database, and there are multiple source- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found