Sometimes I have problems using my BD At Work. Usually is when i try to recover or update a table in Java with the session closed (the famous LazyInitializatioException ).
And at the end, sometimes the problem is that exists a foreign key pointing to a value of a non existing primary key index. When it happens, the lazy entity doesn’t load correctly.
So, is there a way to check if a table data has foreign keys indexes set to non existing primary keys ?
For a single column would be easy. But I mean for tables with about 10 or 20 foreign keys.
Im using postgres. If thats an answer especificaly for it it’d be much better. =]
Sorry for my bad English (not native).
I’m not familiar with Java and those errors you mentioned.
Best solution is to have foreign key constraints created in db which do not allow to remove record if is referenced from another table.
If you must try:
to check if such records exists.
If those tables are big there is no fast solution(usually ends with full table scan).
There is also possibility to do cascade delete or set null automatically using foreign key constraint. Read FOREIGN KEY part in postgresql docs