Unable to save object with relation

Backendless Version 5.x Online

Client SDK Android

Application ID DC9282EA-A192-E6F9-FF38-AF13C1820A00

Expected Behavior

I have a custom class:
public class Surveys {
public String objectId;

public List APs;
public List analyses;

}
AccessPoints and AnalysisPoints are also a custom classes.
There are tables for Surveys, AccessPoints and AnalysisPoints. The Surveys table has a field, “analyses”, with a 1:N relationship with AnalysisPoints and also for AccessPoints.
When I save a Surveys from my app using Backendless.Persistence.of(Surveys.class).save(surveys, new AsyncCallback(){…}), I expect new entries to be made in the AnalysisPoints table with links to the Surveys table entry.

Actual Behavior

While new entries are made to AccessPoints, nothing is added to the AnalysisPoints table and the returned value in handleResponse(Surveys response) no longer has anything in its analyses field.

Hi @daniel-eckhart

take a look at this answer Relation in tables

Regards, Vlad

Thank you for your response. I now am getting the following exception when I try to save a new data object using

Contacts c = new Contacts();
c = Backendless.Data.of(Contacts.class).save( c );

E/MessageQueue-JNI: BackendlessException{ code: 'Internal client exception', message: 'android.os.NetworkOnMainThreadException
    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1450)
    at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:102)
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:90)
    at java.net.InetAddress.getAllByName(InetAddress.java:787)
    at com.android.okhttp.Dns$1.lookup(Dns.java:39)
    at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:197)
    at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:145)
    at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:90)
    at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:190)
    at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:142)
    at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:104)
    at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:392)
    at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:325)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:489)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:262)
    at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
    at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(Unknown Source:0)
    at weborb.client.ioEngine.HttpIOEngine.send(HttpIOEngine.java:195)
    at weborb.client.ioEngine.HttpIOEngine.invoke(HttpIOEngine.java:140)
    at weborb.client.WeborbClient.invoke(WeborbClient.java:138)
    at com.backendless.Invoker.invokeSync(Invoker.java:95)
    at com.backendless.Persistence.save(Persistence.java:144)
    at com.backendless.DataStoreFactory$1.save(DataStoreFactory.java:61)
    at com.randstad.surveyr_cloud.Surveys.upload(Surveys.java:124)
    at com.randstad.surveyr_app.MainActivity.upload(MainActivity.java:1461)
    at com.randstad.surveyr_app.SurveyFragment.onOptionsItemSelected(SurveyFragment.java:287)
    at android.support.v4.app.Fragment.performOptionsItemSelected(Fragment.java:2476)
    at android.support.v4.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:3343)
    at android.support.v4.app.FragmentController.dispatchOptionsItemSelected(FragmentController.java:347)
    at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:413)
    at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
    at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
    at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
    at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:63)
    at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:203)
    at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:780)
    at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
    at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
    at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
    at android.support.v7.view.menu.MenuPopup.onItemClick(MenuPopup.java:127)
    at android.widget.AdapterView.performItemClick(AdapterView.java:350)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1674)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:4085)
    at android.widget.AbsListView.onTouchUp(AbsListView.java:6588)
    at android.widget.AbsListView.onTouchEvent(AbsListView.java:6335)
    at android.widget.ListView.onTouchEvent(ListView.java:1700)
    at android.support.v7.widget.DropDownListView.onTouchEvent(DropDownListView.java:216)

Can you identify this error?

Hi Daniel,

What happens here is you’re using a blocking API call on the main UI thread. Android doesn’t like it. Please see the “Important” block here:
https://backendless.com/docs/android/sync_and_async_calls.html

Regards,
Mark