Error code '1020' when I try to update a user with relation table

Hi,

I have an app where I want to do a relationship between users and comments and another table. I can update comments with my relation table, but I want to update the comment with the user, too. I’m getting this error when I try to update the user:
BackendlessException{ code: ‘1020’, message: ‘Missing ___class property for entity: properties’ }

This is my code:
currentUserId = Backendless.UserService.loggedInUser();

final BackendlessDataQuery query = new BackendlessDataQuery();
QueryOptions queryOptions = new QueryOptions();
queryOptions.setRelationsDepth(1);
query.setQueryOptions( queryOptions );
query.setWhereClause( "objectId = " + “’” + beachId + “’” );

final BackendlessDataQuery queryUser = new BackendlessDataQuery();
QueryOptions queryOptionsUser = new QueryOptions();
queryOptionsUser.setRelationsDepth(1);
queryUser.setQueryOptions( queryOptionsUser );
queryUser.setWhereClause( "objectId = " + “’” + currentUserId + “’” );

new Thread(new Runnable() {
public void run() {
beachToUpdate = Backendless.Persistence.of( Beach.class ).find(query).getData().get(0);
userToUpdate = Backendless.Persistence.of( Users.class ).find(queryUser).getData().get(0);
}
}).start();
comment = new Comment();
comment.setMessage(getCommentFromUser);
comment.setScore(setFinalRatingNumber);
comment.setAuthorEmail(preferences.getString(MainActivity.USER_NAME, “”));
userToUpdate.setEmail("myemail@gmail.com");
userToUpdate.setProperty(“comment”, comment);
userToUpdate.getComment().add(comment);
beachToUpdate.getComment().add(comment);

new Thread(new Runnable() {
public void run() {
Backendless.Persistence.save(beachToUpdate);
Backendless.Persistence.save(userToUpdate);
}
}).start();
I’ve attached a screenshot of my user properties

Hi Salva,

Please, try findById(…) instead of find(…).

Regards,

Denys

Hi Denys,

Still having same problem:
BackendlessException{ code: ‘1020’, message: ‘Missing ___class property for entity: properties’ }

changing this:
userToUpdate = Backendless.Persistence.of( Users.class ).find(queryUser).getData().get(0);
into this:
currentUserId = Backendless.UserService.loggedInUser();
userToUpdate = Backendless.Persistence.of( Users.class ).findById(currentUserId);

Notice that the error is when I try to update the user with the relationship.

You should use BackendlessUser class instead. Where did you get the Users class?

Hi Sergey,

Thanks for your replly:

I’m using the BackendlessUser like and now, I don’t get any error, but the method don’t go throught the handleResponse:

Please, take a look at the screenshot that I’ve attached you. Is of the debug in the BackendlessUser.UserService line. I can see that comment and the required properties are with the user object that is going to update.

Could be this, because comment is relationship with another table, too. This relationship is save correctly, but not with the user.
Backendless.UserService.update(userToUpdate, new AsyncCallback<BackendlessUser>() {

public void handleResponse(BackendlessUser userToUpdate) {
    Toast.makeText(getApplicationContext(),"updated",Toast.LENGTH_LONG).show();
}

public void handleFault(BackendlessFault fault) {

}

});

This is my User class;:
public class Users extends BackendlessUser {

private String objectId;
private ArrayList<Comment> comment;

public String getEmail() {
return super.getEmail();
}

public void setEmail( String email ) {
super.setEmail( email );
}

public String getPassword() {
return super.getPassword();
}

public String getName() {
return (String) super.getProperty( “name” );
}

public void setName( String name ) {
super.setProperty( “name”, name );
}

@Override
public String getObjectId() {
return objectId;
}

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

public ArrayList<Comment> getComment() {
return comment;
}

public void setComment(ArrayList<Comment> items) {
this.comment = items;
}

}

Extending BackendlessUser class is a bad idea and may lead to unexpected behaviour.

Then, what do you mean when you said: “use BackendlessUser class instead”

I mean you need to get rid of the Users class and use BackendlessUser instead. It has setProperty() method with which you can set any property, including a relation. It also has getProperty() and getProperties() which help you retrieve any related data.

I’m using Backendless user now, with setProperty method and same result: any error but don’t set the relationship. I think that the code should be work, but not…

This is all that I’m doing to retrieve the user and set the user with the relationship.

currentUserId = Backendless.UserService.loggedInUser();
final BackendlessDataQuery queryUser = new BackendlessDataQuery();
QueryOptions queryOptionsUser = new QueryOptions();
queryOptionsUser.setRelationsDepth(1);
queryUser.setQueryOptions( queryOptionsUser );
queryUser.setWhereClause( "objectId = " + “’” + currentUserId + “’” );
new Thread(new Runnable() {
public void run() {
userToUpdate = Backendless.Persistence.of( Users.class ).findById(currentUserId);
}
}).start();
BackendlessUser user = userToUpdate;

comment = new Comment();
comment.setMessage(getCommentFromUser);
comment.setScore(setFinalRatingNumber);
comment.setAuthorEmail(preferences.getString(MainActivity.USER_NAME, “”));
user.setEmail("salveta4@gmail.com");
user.setProperty(“comment”, comment);
beachToUpdate.getComment().add(comment);
Backendless.UserService.update(user, new AsyncCallback<BackendlessUser>() {

public void handleResponse(BackendlessUser userToUpdate) {
    Toast.makeText(getApplicationContext(),"updated",Toast.LENGTH_LONG).show();
}

public void handleFault(BackendlessFault fault) {

}

});

How do you know that

userToUpdate = Backendless.Persistence.of( Users.class ).findById(currentUserId);

is executed before

BackendlessUser user = userToUpdate;

You don’t implement any kind of thread synchronization, so the result may not be valid.

Oh, yes. Sorry, maybe I copy/paste wrong. I forget to retrieve the user with the Backenless.UserService.

Now is working, but I have another small issue and is that now is creating two comment at the same time, one set with the user and not with the beach, and the same comment duplicate is set with the beach and not with the comment. This should be for this:

new Thread(new Runnable() {
public void run() {
Backendless.Persistence.save(beachToUpdate);
}
}).start();

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

Change this:

userToUpdate = Backendless.Persistence.of( Users.class ).findById(currentUserId);

Into:
Backendless.UserService.findById(currentUserId, new AsyncCallback<BackendlessUser>() {

public void handleResponse(BackendlessUser userToUpdate) {

    user = userToUpdate;

}

public void handleFault(BackendlessFault fault) {

}

});

Please create a new thread for a new problem, with a detailed description, so that we could better help you.

I’ll try myself first. I think that have the idea of how to do it according with the documentation

Thanks for your help and your time Sergey