Several errors at updating user

Hi all,

My app was working perfectly,but now at the codes I use the API call:

Backendless.UserService.update(user, new AsyncCallback<BackendlessUser>(){....});

the Callback handles faults only, it doesn’t get successful at any time
it showed an error at one calling (Error Code: 1001, Error Message: Cannot update object without any properties: CREATOR)
and showed another error at another calling (Error Code: Server.Processing)
PS, I didn’t edit any of my codes. It happened out of the blue.

any help?

Hello,

What is your application ID?

Mark

Thanks for your quick reply, Mark

my app ID is 6CC67C14-0E25-C794-FF4B-07E445FD5100

I apologize, but I was not able to reproduce the problem.

I just created a test user in your app (you can see the user with the support@backendless.com email) and ran the following code:

BackendlessUser user = // login code here 
user.setProperty( "biography", "awesome user" ); 
Backendless.UserService.update( user, new AsyncCallback<BackendlessUser>() 
{ 
 @Override 
 public void handleResponse( BackendlessUser backendlessUser ) 
 { 
 Log.i( "MYAPP", "user updated" ); 
 } 
 

 @Override 
 public void handleFault( BackendlessFault backendlessFault ) 
 { 
 Log.e( "MYAPP", "Error " + backendlessFault.getDetail() ); 
 } 

The code ran just fine without any problems. I am using the latest build of Android SDK (3.0.25):
https://search.maven.org/#artifactdetails%7Ccom.backendless%7Candroid%7C3.0.25%7Cjar

Regards,
Mark

Thank you for your reply ,Mark
But it still gives me that error, Is it related to my intention to update the user with relations?

Possibly, please create an isolated test program and check at what point user update fails.

Regards,
Mark

Sorry for being late at that reply,

here is the body of onCreate method in a test app adding a post text that been taken from Edit text

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Backendless.initApp(this, "id_code", "secret_id", "version");
    Backendless.Persistence.mapTableToClass("Posts", Posts.class);
    Backendless.Persistence.mapTableToClass("Comments", Comments.class);
    Backendless.UserService.login("email", "password", new AsyncCallback<BackendlessUser>() {
        @Override
        public void handleResponse(BackendlessUser response) {
            BackendlessDataQuery query = new BackendlessDataQuery();
            QueryOptions queryOptions = new QueryOptions();
            queryOptions.addRelated("followings");
            queryOptions.addRelated("followers");
            queryOptions.addRelated("posts");
            queryOptions.addRelated("favorite_items");
            query.setQueryOptions(queryOptions);
            Backendless.Persistence.of(BackendlessUser.class).find(query, new AsyncCallback<BackendlessCollection<BackendlessUser>>() {
                @Override
                public void handleResponse(BackendlessCollection<BackendlessUser> response) {
                    user = response.getCurrentPage().get(0);
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    Log.d("tag", "error");
                }
            });
        }
        @Override
        public void handleFault(BackendlessFault fault) {
            Log.d("tag", "error");
        }
    });
    final EditText text = (EditText) findViewById(R.id.edit_query);
    Button post = (Button) findViewById(R.id.post);
    post.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Posts post = new Posts();
            post.setPostedUser(user);
            post.setPost(text.getText().toString());
            Object[] userPosts = (Object[]) user.getProperty("posts");
            if (userPosts != null) {
                Posts[] posts = new Posts[userPosts.length + 1];
                posts[0] = post;
                System.arraycopy(posts, 1, userPosts, 0, userPosts.length);
                user.setProperty("posts", posts);
                Backendless.UserService.update(user, new AsyncCallback<BackendlessUser>() {
                    @Override
                    public void handleResponse(BackendlessUser response) {
                        Log.e("tag", "success");
                    }

                    @Override
                    public void handleFault(BackendlessFault fault) {
                        Log.e("tag", "failed");
                    }
                });
            }
        }
    });
}

it throws Error Code: 1001, Error Message: Cannot update object without any properties: CREATOR)

What does the Post class look like?

import com.backendless.BackendlessUser;
import java.util.List;

public class Posts {
    private BackendlessUser postedUser;
    private String post;
    private List<Comments> comments;
    private BackendlessUser[] likers;
    private String pictureName;
    private String objectId;

    public Posts() {

    }

    public BackendlessUser getPostedUser() {
        return postedUser;
    }

    public void setPostedUser(BackendlessUser postedUser) {
        this.postedUser = postedUser;
    }

    public String getPost() {
        return post;
    }

    public void setPost(String post) {
        this.post = post;
    }

    public List<Comments> getComments() {
        return comments;
    }

    public void setComments(List<Comments> comments) {
        this.comments = comments;
    }

    public BackendlessUser[] getLikers() {
        return likers;
    }

    public void setLikers(BackendlessUser[] likers) {
        this.likers = likers;
    }

    public String getPictureName() {
        return pictureName;
    }

    public void setPictureName(String pictureName) {
        this.pictureName = pictureName;
    }

    public String getObjectId() {
        return objectId;
    }

    public void setObjectId(String objectId) {
        this.objectId = objectId;
    }

    public boolean equals(Posts i) {
        if (post.equals(i.post)
                && postedUser.getObjectId().equals(i.postedUser.getObjectId())) return true;
        return false;
    }
}

Here’s a problem I see in your schemas:

The Posts table has auto-load enabled for Comments and Users(“likers” and “postedUser” columns).

When you update a user object by adding a Posts object, you could be creating a rather complex hierarchy of objects because Posts may be referencing the same user object you’re adding it too.

I would recommend turning off ALL your auto-load properties to simplify the relations between objects on the client side. Auto-load is great for simple tests and prototypes, but it should not be used for production quality apps because it could leads to problems like this one.

Mark

Okay it’s good to improve the performance, but the problem comes from updating the user before getting to execute the API of post

The problem is how you configured the data to load. You’re adding Posts to a user which may already have some posts. Those posts the user already had may be referencing others users with posts and comments, and ALL of it is sent to the server for update.

Just try the following:
Create new user and add a new Posts object to it. Save the user. Does the problem happen? I do not think it would, because all of the complexity in the hierarchy does not exist in that case.

Mark

Actually, another Error code appeared (Error Code: Server.Processing) while adding a new post

Just ran the following code and it worked just fine:

BackendlessUser user = new BackendlessUser(); 
user.setEmail( "support@backendless.com" ); 
user.setPassword( "password" ); 
user.setProperty( "username", "backendlesssupport" ); 
 

Posts posts = new Posts(); 
posts.setPost( "test post" ); 
user.setProperty( "posts", new Posts[] { posts } ); 
Backendless.UserService.register( user, new AsyncCallback<BackendlessUser>() 
{ 
 @Override 
 public void handleResponse( BackendlessUser backendlessUser ) 
 { 
 

 } 
 

 @Override 
 public void handleFault( BackendlessFault backendlessFault ) 
 { 
 

 } 
} );

For us to continue, you need to create a minimal example which demonstrates a problem.

Regards,
Mark