Realm Android can't copyOrUpdate object without primary key

Please try

FavoriteSong favoriteSong = ...favorite song from server
mRealm.executeTransaction(new Realm.Transaction() {
        @Override
        public void execute(Realm realm) {
            Song tempSong = favoriteSong.getSong();
            favoriteSong.setSong(null);
            FavoriteSong savedFavoriteSong = realm.copyToRealm(favoriteSong);
            Song dbSong = realm.where(Song.class).equalTo(SongFields.ID, tempSong.getId()).findFirst();
            if(dbSong == null) {
                dbSong = realm.copyToRealmOrUpdate(tempSong);
            }
            savedFavoriteSong.setSong(dbSong);
        }

The SongFields is assuming you are using https://github.com/cmelchior/realmfieldnameshelper