User Table Relation not working properly

I’ve added a Table Relation to the user object.

Then I added a related object to a particular user.

When the user logs in he gets the object including the related object.

“profilePicture”:{“bodyTextColor”:"-1811939328",“imageId”:“e2abe38bd5a55eba0718f05d423a68b37404c86c”,“updated”:“Dec 23, 2015 6:45:21 PM”,“dir”:“d276571e4b48e43a14ea647a35c39d7d3e13fbe7”,“created”:“Dec 23, 2015 6:45:11 PM”,“backgroundColor”:"-2047888",“objectId”:“B79E3CEE-AC5B-0A38-FF66-0F70B874B900”,“ownerId”:“FF811850-3FEC-3041-FFDC-482366766E00”,“titleTextColor”:“1912602624”,“imgHash”:“3893d1260455d960191c2da60c557de0a35cd86a”,"___class":“Image”}

If i then try to save the user object I get the following error:

BackendlessException{ code: ‘IllegalArgumentException’, message: ‘ProfilePicture’ }
Caused by: java.lang.NoSuchFieldException: ProfilePicture

In my data browser, the variable exists and the relationship is visible.
Any clues?

Regards,
Jens

Do you save with REST? Either way (REST or native), could you show the request/code you use to save the object?

Regards,
Mark

Image image = ImgHelper.sendImage(uri);
BackendlessUser backendlessUser = getBackendlessUser();
backendlessUser.setProperty("profilePicture",image);
backendlessUser = Backendless.Data.of(BackendlessUser.class).save(backendlessUser);

But i also tried to save the related object via Data Console.
Both ways i was able to retrieve the object.
If I then try to save the “exact” same object i get the error.

What is the name of the related table where instances of the Image class are stored?

“profilePicture”
I’ve also tried first letter upper/lowercase, no change.

try adding this line before you use any of the APIs (after initApp though):

Backendless.Data.mapTableToClass( "profilePicture", Image.class )

Mark

Including your advised code I get the following error:

BackendlessException{ code: ‘1023’, message: ‘Relation type update is prohibited - property profilePicture must relate to table Image but not profilePicture’ }

Can you post the following:

  1. a screenshot of the Users>UserProperties screen?
  2. the code for the Image class
  3. schema for the table where instances of the Image class are stored

Regards,
Mark

Sent you the information via mail.

Thanks, I got it.

I gave you wrong instructions. The mapping call should look like this:

Backendless.Data.mapTableToClass( "Image", Image.class )

Could you try it again with that instead?

Regards,
Mark

After I’ve put in your peace of code:

BackendlessException{ code: ‘IllegalArgumentException’, message: ‘ProfilePicture’ }
Caused by: java.lang.NoSuchFieldException: ProfilePicture

Are you using the latest build of SDK?

Yes, using latest build just downloaded from your website. (3.0.0)

Btw. I’ve printed out the User Class via client:

[{“identity”:false,“name”:“objectId”,“type”:“STRING_ID”,“required”:false},{“identity”:false,“name”:“ownerId”,“type”:“STRING”,“required”:false},{“identity”:false,“name”:“password”,“type”:“STRING”,“required”:true},{“identity”:false,“name”:“updated”,“type”:“DATETIME”,“required”:false},{“identity”:false,“name”:“deviceId”,“type”:“STRING”,“required”:false},{“identity”:false,“name”:“created”,“type”:“DATETIME”,“required”:false},{“identity”:true,“name”:“email”,“type”:“STRING”,“required”:true},{“identity”:false,“name”:“alias”,“type”:“STRING”,“required”:true},{“identity”:false,“name”:“profilePicture”,“type”:“RELATION”,“required”:false}]

looks OK to me.

Hi Jens,

We were able to reproduce the problem. It has been fixed in the SDK. You can download the latest build from:
https://github.com/Backendless/Android-SDK/tree/master/out

We will be pushing it to maven and our website shortly.

Regards,
Mark

With this update i get the following error:

BackendlessException{ code: ‘1001’, message: ‘Cannot update object without any properties: profilePicture’ }

After I changed the relation name from “profilePicture” to “ProfilePicture” I get a different error:

BackendlessException{ code: ‘8001’, message: ‘Duplicate property: ProfilePicture’ }

(for this I had to name the property in Android code “profilePicture”. If i started with an uppercase letter I got 1001 again.)

This is the code I use to test the use-case and it is working for me with the updated jar. How different is it from yours?

Backendless.Data.mapTableToClass( “Image”, Image.class );
Image image = new Image();
image.setBackgroundColor( “white” );
image.setDir( “/foo” );
BackendlessUser backendlessUser = Backendless.UserService.login( userName, password );
backendlessUser.setProperty( “profilePicture”,image );
backendlessUser = Backendless.Data.of(BackendlessUser.class).save(backendlessUser);

Hi Jens,

There was another update for backendless.jar. Could you please grab the latest and try again?

Thanks,
Mark

Hey Mark,

the updated .jar did the trick!
Thank you very much!!

Jens