When I set a user property that is a data object of another class, it creates a duplicate. I am certain that this is caused when it tries to set the property with objects that don’t reflect the same data as the objects that are still in the database. This problem doesn’t occur when I work with objects that are the same as the database, but the objects change due to the fact that multiple users access them and change them constantly. How can I get past this?
Hi Manenga,
Could you please create a sample demonstrating the problem and post it here? You can leave the appid/secret key as blank and we configure it with one of our apps.
Regards,
Mark
I’m not entirely sure what you mean by create a sample but I will post extracts of the code and the class. IF that doesn’t help, please let me know what else I can send.
public void saveOnCloud(String title, final boolean status){ //status is whether the user wants to like the song or unlike it
BackendlessDataQuery q = new BackendlessDataQuery();
q.setWhereClause(“trackTitle = '”+ title +"’"); //the song is queried
System.out.println("Current Likes Before: "+liked.size());
final BackendlessUser user = Backendless.UserService.CurrentUser();
Backendless.Data.of(Songs.class).find(q, new AsyncCallback<BackendlessCollection<Songs>>() {
@Override
public void handleResponse(BackendlessCollection<Songs> response) {
List list = response.getCurrentPage();
if(list != null && list.size() > 0){
Songs likedSong = (Songs) list.get(0);
if(status){ //if the user wants to like the song
likedSong.likes += 1;
liked.add(likedSong);
System.out.println("Current Likes After: "+liked.size());
}
else { //if the user wants to unlike the song
if(liked.contains(likedSong)) {
liked.remove(likedSong);
}
else {
for (Songs like: liked) {
if(like.trackTitle.equalsIgnoreCase(likedSong.trackTitle) && like.artistName.equalsIgnoreCase(likedSong.artistName)){
liked.remove(like);
break;
}
}
}
}
Songs[] l = new Songs[liked.size()];
for (int i = 0; i < liked.size(); i++) {
l = liked.get(i);
}
user.setProperty("likes", l); //for some reason it wouldn't accept an arraylist
}
Backendless.UserService.update(user, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
System.out.println("Awe: "+response.toString());
}
@Override
public void handleFault(BackendlessFault fault) {
System.out.println("Fault: "+fault.getMessage());
}
});
}
@Override
public void handleFault(BackendlessFault fault) {}
});
}
This is the songs class that I keep referring to:public class Songs {
String artistName;
String duration;
int plays = 0;
int likes = 0;
String song;
String genre;
String trackTitle;
String image;
public Songs(){}
}Please find attached, the schema and sample data in the table (including duplicates)
What would be great if you could run export on your data and schema and send us the export file. The export interface is available at Manage > Export.
Thanks!
Can I send it to you privately via email?
Sure, please send it to support@backendless.com. Make sure to include the link for this topic in support.
done