Search code examples
androidlazy-loadingormliteeager-loadingforeign-collection

OrmLite ForeignCollectionField is eager loaded always?


I am using OrmLite 4.48 and I've setup two objects in the following way: (simplified)

public class Chat {
     @ForeignCollectionField(eager = false)
     private ForeignCollection<ChatUser> chatUsers;
}

public class ChatUser {
     @DatabaseField(foreign = true)
     private Chat chat;
}

Unfortunately when i query Chat objects from the DB i always see through debug that ChatUser objects are completely loaded? As its stated in the docs, the foreign collections are lazy by default but in my case i see its otherwise?

BTW, if i load the ChatUser objects independently through a query i can see that their Chat foreign fields only have ids loaded (as expected)...

I assume the error is something obvious i missed but i dont see how this could be any simpler?


Solution

  • It turns out the debugger itself is causing the additional queries which causes the lazy collections to be fetched :) (it occurred to me, but didnt think it was really happening :) ).

    I've also found another question with the answer explained by @Gray (https://stackoverflow.com/users/179850/gray)

    https://stackoverflow.com/a/7244121/1865583