ClassCastException to java.util.CollectionServiceException

I have a User and 2 custom objects, Business and Member. User has a bidirectional 1:N with Member. Member has a birirectional N:1 with Business. I have a business logic service which creates a new Business and initial Member for the logged in User. The relationships are all modelled as List<XXX>.

Creating and associating all the objects works fine. I then call

firstMember = Backendless.Persistence.of(Member.class).save(firstMember);

to save the object graph. Everything saves, but the response of the service is an exception. This seems to be from the result of the save being converted back into a Member instance to be returned from the service. The exception is

"java.lang.ClassCastException: [Lcom.mbaas.model.Member; cannot be cast to java.util.CollectionServiceException"

I have called

Backendless.Data.mapTableToClass(“Member”, Member.class);
Backendless.Data.mapTableToClass(“Business”, Business.class);

when the service is created.

Not sure where to go as I have no idea what CollectionServiceException is or why there is a plain list of Members.

I changed the save to

Backendless.UserService.update(user);

but the issue is the same. I’m guessing it’s something to do with the relationship from the User to the Member because it isn’t explicitly modelled where as there are specific classes for the other 2, both using List. I see I’m not allowed to subclass the BackendlessUser class.

Interestingly, though I see the User updated and the new Member and Business instances listed in the data browser, when I GET the user in the REST console the members list is empty.

I was also considering removing the relationship from User to Member and querying for Members whose user is the currently logged in user. I guess I can do that using the user objectId.

I’m no closer to understanding the cause of the issue, but at least I have a work around in that if I don’t set the relationship on the User and instead query for Member instances as I described above using the user.objectId then everything works to save and query back the instances.

Hi Wain,

Could you please provide the following to help us with diagnosing the problem:

    Complete stack trace of the error Screenshots showing the Member, Business and Users schemas Class definitions for Member and Business.
Regards, Mark

Reply made by e-mail, Thanks

Hi Wain,

I tried identical approach in my test app and could not reproduce the problem. There were a few fixes in our SDK for Android related to the problem you experienced. Could you please grab a copy of the latest build from the URL below and try it again?
https://github.com/Backendless/Android-SDK/blob/master/out/backendless.jar

Regards,
Mark