martyn mlostekk martyn mlostekk - 1 year ago 83
Android Question

RealList in RealmObject not automatically loaded

i am having the following issue:

This is the class for


public class ProjectInfo extends RealmObject
@Getter @Setter @PrimaryKey private long projectId;
@Getter @Setter RealmList<Submission> submissions;

And this is the class for

public class Submission extends RealmObject
@Getter @Setter @PrimaryKey long id;
@Getter @Setter Date creationDate;

public Submission() {}


When i create the objects and save to the realm database, the reference from ProjectInfo to Submission is shown like this in the column


This looks right.

But now when i load the projectInfo object with

ProjectInfo projectInfo = realm.where(ProjectInfo.class).equalTo("projectId", projectId).findFirst();

The projectInfo.submissions == null;

Do i have to do something special to automatically load references from other tables?

I am using realm version

classpath 'io.realm:realm-gradle-plugin:2.1.1'

The @Getter and @Setter are from projectLombok.


While debugging i see a member called
in the
class which has the correct values. But they are not written into the
member. What is the reason?

Answer Source

Of course not. All fields inside a RealmProxy are lazy-loaded. You obtain the list via getSubmissions(), which will return the list that contains the proxies of the elements. The fields themselves are just to provide the underlying Realm schema (and to load them with data for unmanaged objects, which Realm uses to populate the underlying Realm when you call insertOrUpdate or copyToRealmOrUpdate)

But this is all mentioned in the documentation:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download