I'm trying to figure out the issue when I have a POJO with Embedded and one-to-many Relation, and the auto-generated code picks up improper column index for the cursor. The problem is that it confuses columns from the Identity and the Scan, and sets the Scan values to those of the Identity from the JOIN.

I've already checked the The field's same name issue in the tables, when join tables in ROOM answers, and it doesn't seem to do the trick as it fails to generate compilable code for the POJO. I have two classes, Scan and Identity, they are retrieved through

@Query("SELECT * FROM scans JOIN identities on scans.identity_id = identities.rid WHERE scans.id  IN (:ids) AND scans.deleted_at IS NULL ORDER BY scans.updated_at DESC")
Flowable<List<ScanAndIdentity>> findAllWithIdentity(long[] ids);

There's also the POJO:

public class ScanAndIdentity {
    public Scan scan;

    @Relation(parentColumn = "identity_id", entityColumn = "rid", entity = 
    public List<Identity> identities;

How can I get around this issue? I tried with prefix in the Embedded, but that also gives an error Not sure how to convert a Cursor to this method's return type (*.pojo.ScanAndIdentity)

0 Answers