public static void trackIdChange ( final ODocument document , final Object pojo ) { if ( document . getIdentity ( ) . isNew ( ) ) { ORecordInternal . addIdentityChangeListener ( document , new OIdentityChangeListener ( ) { @ Override public void onBeforeIdentityChange ( final ORecord record ) { // not needed } @ Override public void onAfterIdentityChange ( final ORecord record ) { OObjectSerializerHelper . setObjectID ( record . getIdentity ( ) , pojo ) ; OObjectSerializerHelper . setObjectVersion ( record . getVersion ( ) , pojo ) ; } } ) ; } }
When just created object is detached to pure pojo it gets temporary id . Real id is assigned only after transaction commit . This method tracks original document intercepts its id change and sets correct id and version into pojo . So it become safe to use such pojo id outside of transaction .