Buggy code:
class VersionAttachStrategy extends AttachStrategy implements DetachState { private static final Localizer _loc = Localizer . forPackage ( VersionAttachStrategy . class ) ; protected Object getDetachedObjectId ( AttachManager manager , Object toAttach ) { } protected void provideField ( Object toAttach , StateManagerImpl sm , int field ) { } public Object attach ( AttachManager manager , Object toAttach , ClassMetaData meta , PersistenceCapable into , OpenJPAStateManager owner , ValueMetaData ownerMeta , boolean explicit ) { BrokerImpl broker = manager . getBroker ( ) ; PersistenceCapable pc = ImplHelper . toPersistenceCapable ( toAttach , meta . getRepository ( ) . getConfiguration ( ) ) ; boolean embedded = ( ownerMeta != null ) && ( ownerMeta . isEmbeddedPC ( ) ) ; boolean isNew = ! ( broker . isDetached ( pc ) ) ; Object version = null ; StateManagerImpl sm ; if ( embedded && ( ( isNew || ( into == null ) ) || ( ( broker . getStateManager ( into ) ) == null ) ) ) { if ( into == null ) into = pc . pcNewInstance ( null , false ) ; sm = ( ( StateManagerImpl ) ( broker . embed ( into , null , owner , ownerMeta ) ) ) ; into = sm . getPersistenceCapable ( ) ; } else if ( isNew ) { Object oid = null ; if ( ! ( isPrimaryKeysGenerated ( meta ) ) ) oid = ApplicationIds . create ( pc , meta ) ; sm = persist ( manager , pc , meta , oid , explicit ) ; into = sm . getPersistenceCapable ( ) ; } else if ( ( ! embedded ) && ( into == null ) ) { Object id = getDetachedObjectId ( manager , toAttach ) ; if ( id != null ) into = ImplHelper . toPersistenceCapable ( broker . find ( id , true , null ) , broker . getConfiguration ( ) ) ; if ( into == null ) throw new org . apache . openjpa . util . OptimisticException ( VersionAttachStrategy . _loc . get ( "attach-version-del" , ImplHelper . getManagedInstance ( pc ) . getClass ( ) , id , version ) ) . setFailedObject ( toAttach ) ; sm = manager . assertManaged ( into ) ; if ( ( meta . getDescribedType ( ) ) != ( sm . getMetaData ( ) . getDescribedType ( ) ) ) { throw new org . apache . openjpa . util . ObjectNotFoundException ( VersionAttachStrategy . _loc . get ( "attach-wrongclass" , id , toAttach . getClass ( ) , sm . getMetaData ( ) . getDescribedType ( ) ) ) . setFailedObject ( toAttach ) ; } } else sm = manager . assertManaged ( into ) ; manager . setAttachedCopy ( toAttach , into ) ; if ( pc == into ) { attachFieldsInPlace ( manager , sm ) ; return into ; } if ( isNew ) { broker . fireLifecycleEvent ( toAttach , null , meta , BEFORE_PERSIST ) ; } else { manager . fireBeforeAttach ( toAttach , meta ) ; } StateManager smBefore = pc . pcGetStateManager ( ) ; pc . pcReplaceStateManager ( sm ) ; int detach = ( isNew ) ? DETACH_ALL : broker . getDetachState ( ) ; FetchConfiguration fetch = broker . getFetchConfiguration ( ) ; try { <START_BUG> FieldMetaData [ ] fmds = meta . getFields ( ) ; <END_BUG> for ( int i = 0 ; i < ( fmds . length ) ; i ++ ) { switch ( detach ) { case DETACH_ALL : attachField ( manager , toAttach , sm , fmds [ i ] , true ) ; break ; case DETACH_FETCH_GROUPS : if ( ( fetch . requiresFetch ( fmds [ i ] ) ) != ( FetchConfiguration . FETCH_NONE ) ) attachField ( manager , toAttach , sm , fmds [ i ] , true ) ; break ; case DETACH_LOADED : attachField ( manager , toAttach , sm , fmds [ i ] , false ) ; break ; } } } finally { pc . pcReplaceStateManager ( smBefore ) ; } if ( ( ! embedded ) && ( ! isNew ) ) compareVersion ( sm , pc ) ; return ImplHelper . getManagedInstance ( into ) ; } private void compareVersion ( StateManagerImpl sm , PersistenceCapable pc ) { } private void attachFieldsInPlace ( AttachManager manager , StateManagerImpl sm ) { } private Object attachInPlace ( AttachManager manager , StateManagerImpl sm , ValueMetaData vmd , Object pc ) { } private Object [ ] attachInPlace ( AttachManager manager , StateManagerImpl sm , FieldMetaData fmd , Object [ ] arr ) { } private Collection attachInPlace ( AttachManager manager , StateManagerImpl sm , FieldMetaData fmd , Collection coll ) { } private Map attachInPlace ( AttachManager manager , StateManagerImpl sm , FieldMetaData fmd , Map map ) { } protected PersistenceCapable findFromDatabase ( AttachManager manager , Object pc ) { } private boolean isPrimaryKeysGenerated ( ClassMetaData meta ) { } }

Fix:
FieldMetaData [ ] fmds = sm . getMetaData ( ) . getFields ( ) ;