Buggy code:
public class RelationRelationMapTableFieldStrategy extends MapTableFieldStrategy { private static final Localizer _loc = Localizer . forPackage ( RelationRelationMapTableFieldStrategy . class ) ; private String _keyRelationName = null ; public Column [ ] getKeyColumns ( ClassMapping cls ) { } public Column [ ] getValueColumns ( ClassMapping cls ) { } public void selectKey ( Select sel , ClassMapping key , OpenJPAStateManager sm , JDBCStore store , JDBCFetchConfiguration fetch , Joins joins ) { } public void selectValue ( Select sel , ClassMapping val , OpenJPAStateManager sm , JDBCStore store , JDBCFetchConfiguration fetch , Joins joins ) { } public Result [ ] getResults ( final OpenJPAStateManager sm , final JDBCStore store , final JDBCFetchConfiguration fetch , final int eagerMode , final Joins [ ] resJoins , boolean lrs ) throws SQLException { } public Object loadKey ( OpenJPAStateManager sm , JDBCStore store , JDBCFetchConfiguration fetch , Result res , Joins joins ) throws SQLException { } public Object loadValue ( OpenJPAStateManager sm , JDBCStore store , JDBCFetchConfiguration fetch , Result res , Joins joins ) throws SQLException { } public Joins joinKeyRelation ( Joins joins , ClassMapping key ) { } public Joins joinValueRelation ( Joins joins , ClassMapping val ) { } public void map ( boolean adapt ) { } private void mapTypeJoin ( ValueMapping vm , DBIdentifier name , boolean adapt ) { } public void initialize ( ) { } public void insert ( OpenJPAStateManager sm , JDBCStore store , RowManager rm ) throws SQLException { } private void insert ( OpenJPAStateManager sm , RowManager rm , Map map , JDBCStore store ) throws SQLException { } public void update ( OpenJPAStateManager sm , JDBCStore store , RowManager rm ) throws SQLException { if ( ( ( field . getMappedBy ( ) ) != null ) && ( ! ( field . isBiMTo1JT ( ) ) ) ) return ; Map map = ( ( Map ) ( sm . fetchObject ( field . getIndex ( ) ) ) ) ; ChangeTracker ct = null ; if ( map instanceof Proxy ) { Proxy proxy = ( ( Proxy ) ( map ) ) ; if ( Proxies . isOwner ( proxy , sm , field . getIndex ( ) ) ) ct = proxy . getChangeTracker ( ) ; } if ( ( ct == null ) || ( ! ( ct . isTracking ( ) ) ) ) { delete ( sm , store , rm ) ; insert ( sm , rm , map , store ) ; return ; } ValueMapping key = field . getKeyMapping ( ) ; ValueMapping val = field . getElementMapping ( ) ; StoreContext ctx = store . getContext ( ) ; OpenJPAStateManager keysm ; OpenJPAStateManager valsm ; Collection change = ct . getChanged ( ) ; boolean canChange = val . getForeignKey ( ) . isLogical ( ) ; Object mkey ; if ( canChange && ( ! ( change . isEmpty ( ) ) ) ) { Row changeRow = null ; if ( ! ( field . isUni1ToMFK ( ) ) ) { <START_BUG> rm . getSecondaryRow ( field . getTable ( ) , ACTION_UPDATE ) ; <END_BUG> changeRow . whereForeignKey ( field . getJoinForeignKey ( ) , sm ) ; } for ( Iterator itr = change . iterator ( ) ; itr . hasNext ( ) ; ) { mkey = itr . next ( ) ; Object mval = map . get ( mkey ) ; if ( mval == null ) { Set < Map . Entry > entries = map . entrySet ( ) ; for ( Map . Entry entry : entries ) { if ( entry . getKey ( ) . equals ( mkey ) ) mval = entry . getValue ( ) ; } } if ( mval == null ) continue ; keysm = RelationStrategies . getStateManager ( mkey , ctx ) ; valsm = RelationStrategies . getStateManager ( mval , ctx ) ; key . whereForeignKey ( changeRow , keysm ) ; if ( field . isUni1ToMFK ( ) ) { changeRow = rm . getRow ( field . getElementMapping ( ) . getDeclaredTypeMapping ( ) . getTable ( ) , ACTION_UPDATE , valsm , true ) ; changeRow . wherePrimaryKey ( valsm ) ; val . setForeignKey ( changeRow , sm ) ; } else { val . setForeignKey ( changeRow , valsm ) ; rm . flushSecondaryRow ( changeRow ) ; } } } Collection rem = ct . getRemoved ( ) ; if ( ( ! ( rem . isEmpty ( ) ) ) || ( ( ! canChange ) && ( ! ( change . isEmpty ( ) ) ) ) ) { Row delRow = null ; if ( ! ( field . isUni1ToMFK ( ) ) ) { delRow = rm . getSecondaryRow ( field . getTable ( ) , ACTION_DELETE ) ; delRow . whereForeignKey ( field . getJoinForeignKey ( ) , sm ) ; } for ( Iterator itr = rem . iterator ( ) ; itr . hasNext ( ) ; ) { Object pc = itr . next ( ) ; if ( field . isUni1ToMFK ( ) ) { updateSetNull ( sm , rm , pc ) ; } else { keysm = RelationStrategies . getStateManager ( pc , ctx ) ; key . whereForeignKey ( delRow , keysm ) ; rm . flushSecondaryRow ( delRow ) ; } } if ( ( ! canChange ) && ( ! ( change . isEmpty ( ) ) ) ) { for ( Iterator itr = change . iterator ( ) ; itr . hasNext ( ) ; ) { Object pc = itr . next ( ) ; if ( field . isUni1ToMFK ( ) ) { updateSetNull ( sm , rm , pc ) ; } else { keysm = RelationStrategies . getStateManager ( pc , ctx ) ;

Fix:
changeRow = rm . getSecondaryRow ( field . getTable ( ) , ACTION_UPDATE ) ;