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 ) { BrokerImpl broker = manager . getBroker ( ) ; PersistenceCapable pc = ( ( PersistenceCapable ) ( toAttach ) ) ; boolean embedded = ( ownerMeta != null ) && ( ownerMeta . isEmbeddedPC ( ) ) ; boolean isNew = ! ( broker . isDetached ( pc ) ) ; Object version = null ; StateManagerImpl sm = null ; 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 ) { sm = persist ( manager , pc , meta , ApplicationIds . create ( pc , meta ) ) ; into = sm . getPersistenceCapable ( ) ; } else if ( ( ! embedded ) && ( into == null ) ) { Object id = getDetachedObjectId ( manager , toAttach ) ; if ( id != null ) into = ( ( PersistenceCapable ) ( broker . find ( id , true , null ) ) ) ; if ( into == null ) throw new org . apache . openjpa . util . OptimisticException ( VersionAttachStrategy . _loc . get ( "attach-version-del" , 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 ; } manager . fireBeforeAttach ( toAttach , meta ) ; pc . pcReplaceStateManager ( sm ) ; int detach = ( isNew ) ? DETACH_ALL : broker . getDetachState ( ) ; FetchConfiguration fetch = broker . getFetchConfiguration ( ) ; try { FieldMetaData [ ] fmds = meta . getFields ( ) ; for ( int i = 0 ; i < ( fmds . length ) ; i ++ ) { switch ( detach ) { case DETACH_ALL : attachField ( manager , toAttach , sm , fmds [ i ] , true ) ; break ; case DETACH_FGS : <START_BUG> if ( ( ( fmds [ i ] . isInDefaultFetchGroup ( ) ) || ( fetch . hasFetchGroup ( fmds [ i ] . getFetchGroups ( ) ) ) ) || ( fetch . hasField ( fmds [ i ] . getFullName ( ) ) ) ) <END_BUG> attachField ( manager , toAttach , sm , fmds [ i ] , true ) ; break ; case DETACH_LOADED : attachField ( manager , toAttach , sm , fmds [ i ] , false ) ; break ; } } } finally { pc . pcReplaceStateManager ( null ) ; } if ( ( ! embedded ) && ( ! isNew ) ) compareVersion ( sm , pc ) ; return 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 ) { } }

Fix:
if ( ( ( fmds [ i ] . isInDefaultFetchGroup ( ) ) || ( fetch . hasAnyFetchGroup ( fmds [ i ] . getFetchGroups ( ) ) ) ) || ( fetch . hasField ( fmds [ i ] . getFullName ( ) ) ) )