Android saving row in table with data relations to same table

Similar to my other issue (which is now fixed, thanks): http://support.backendless.com/t/missing-relations-returned-with-autoload
Table A has a column named components which is a one to many data relationship to itself (Table A).
Components is set to autoload.
Row 1 has an empty list of components,
Row 2 has 1 component: Row 1.
When using the Android SDK to save Row 2, I always get back:
java.lang.RuntimeException: Unable to save object - invalid data type for properties - components. You can change the property type in developer console.
This was also occurring before the above topic was fixed, but I thought that since it seemed to be trying to save a null value (since it wasn’t auto loading), that was the cause.
All of the member fields look fine when passing the Row 2 object into the save method Backendless.Data.of(TableA.class).save(…)
I think this is occurring because the Row 1 components is an empty list?
Adding Row 1 to Row 2’s components was achieved by using the REST console - so that seems to work fine.
If I save Row 1 with no components, everything works.
If I add Row 2 in Row 1’s components, I get:
java.lang.RuntimeException: java.lang.StackOverflowError
Which I would expect (needs client side logic to avoid cyclic references)

Hi James,

Just to confirm I understood the scenario correctly:

    Row1 object is saved and has no "components". When Row2 is being saved and if it references Row1 in the "components" list, you are getting the StackOverflowError.
Please confirm if this is correct. Also, in that case, please clarify under what circumstances you're getting the following error: "java.lang.RuntimeException: Unable to save object - invalid data type for properties - components"

Regards,
Mark

Hi James!

  1. I can reproduce issue with “java.lang.RuntimeException: Unable to save object - invalid data type for properties…”. We will fix it on the next week.
  2. I also need more information about steps to receive StackOverflowError.
    Regards,
    Kate.

To reproduce StackOverflowError, you need to create a cyclic reference between 2 (or more) rows.

If Row 1’s components contains Row 2, and you try to update Row 2’s components to include Row 1, it StackOverflowErrors.

I thought this was “as designed”, but just tried it in the Data Browser and it worked.

Could you try it with this backendless.jar?

I believe that .jar is pointing to 127.0.0.1 rather than backendless.com

Backendless.java:
private static String url = “http://localhost:9000”;

Could you set proper host using
Backendless.setUrl( “http://api.backendless.com”);
in your code?
Sorry, wrong url added by mistake.

The updated .jar (pointing at the correct url) doesn’t appear to fix the issue:

TableA.findFirstAsync(new BackendlessCallback<TableA>() {
            @Override
            public void handleResponse(final TableA first) {
                TableA.findLastAsync(new BackendlessCallback<TableA>() {
                    @Override
                    public void handleResponse(TableA last) {
                        ArrayList<TableA> list = new ArrayList<>();
                        list.add(last);
                        first.setComponents(list);
//                        list = new ArrayList<>();
//                        list.add(first);
//                        last.setComponents(list);


                        first.saveAsync(new BackendlessCallback<TableA>() {
                            @Override
                            public void handleResponse(TableA tableA) {
                                Log.i("yay", "first saved");
                            }
                        });
//                        last.saveAsync(new BackendlessCallback<TableA>() {
//                            @Override
//                            public void handleResponse(TableA tableA) {
//                                Log.i("yay", "last saved");
//                            }
//                        });
                    }
                });
            }
        });

Gives:

FATAL EXCEPTION: main
Process: com.dejamgames.dbeditor, PID: 23917
java.lang.RuntimeException: Unable to save object - invalid data type for properties - components. You can change the property type in developer console.
at com.backendless.async.callback.BackendlessCallback.handleFault(BackendlessCallback.java:28)
at com.backendless.Persistence$4.handleFault(Persistence.java:201)
at com.backendless.async.message.AsyncMessage$FaultHandler.handle(AsyncMessage.java:83)
at com.backendless.async.message.AsyncMessage.handleCallback(AsyncMessage.java:41)
at com.backendless.core.AndroidCarrier$1.handleMessage(AndroidCarrier.java:37)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

If you uncomment the commented code, you get:

FATAL EXCEPTION: main
Process: com.dejamgames.dbeditor, PID: 26729
java.lang.RuntimeException: java.lang.StackOverflowError
at com.backendless.async.callback.BackendlessCallback.handleFault(BackendlessCallback.java:28)
at com.backendless.Persistence$4.handleFault(Persistence.java:201)
at com.backendless.async.message.AsyncMessage$FaultHandler.handle(AsyncMessage.java:83)
at com.backendless.async.message.AsyncMessage.handleCallback(AsyncMessage.java:41)
at com.backendless.core.AndroidCarrier$1.handleMessage(AndroidCarrier.java:37)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Hello, any progress on this question?

Anton, I apologize it is taking a bit longer than we anticipated. It is in the support queue and we’ll be looking into it very soon.

Regards,
Mark

Hi Anton, James,

Does the issue still affects you?

Regards, Artur.

I’m also experiencing something close to this im failing to return the row that was clicked with the correct information

Hello,

This topic is 2 years old and marked as solved.
Please create a new one and provide more details about your problem - your APP ID and steps to reproduce this issue.

Regards, Olga