DB2 Error Code 311 – The optimizer could not find a unique index which it could use to scan table ‘%s’ for cursor ‘jconnect_implicit_%d’

In this post, you’ll learn about the DB2 error 311-The optimizer could not find a unique index which it could use to scan table ‘%s’ for cursor ‘jconnect_implicit_%d’ and the reason why you are receiving the error message and how to fix it

How does this Error Message Looks like

311 – The optimizer could not find a unique index which it could use to scan table ‘%s’ for cursor ‘jconnect_implicit_%d’

Reason for the Error & Solution

A pessimistic lock was attempted on a table that does not have a primary key (or other unique index). By default, the Kodo mapping tool does not create primary keys for join tables. In order to use datastore locking for relations, an IDENTITY column should be added to any tables that do not already have them.