DBFlow - using foreign key with integer type

1.2k Views Asked by At

I'm a newbie on Android. I have a trouble when use DBFlow to mapping database on my application.

Firstly, I will talk about my database schema.

Collection (msg_key INTEGER PRIMARY KEY , message_id INTEGER, ...)

Message (message_id : INTEGER PRIMARY KEY, ...)

And my Java code on same package,

Message class:

@Table(database = MyDatabase.class, name = Constants.TBL_MESSAGE, allFields = true)
public class Message extends BaseModel {

    @PrimaryKey
    int message_id;
    String description;
}

Collection class:

@Table(database = MyDatabase.class, name = Constants.TBL_COLLECTION, allFields = true)
public class Collection extends BaseModel {
    @Column(setterName = "setMsg_key", getterName = "getMsg_key")
    @PrimaryKey
    private int msg_key;

    @Column(setterName = "setMessage_id", getterName = "getMessage_id")
    @ForeignKey(references = {
            @ForeignKeyReference(columnType = Integer.class,
                    columnName = Constants.TBL_COL_MSG,
                    foreignKeyColumnName = Constants.TBL_MSG_ID)}
            , saveForeignKeyModel = false)
    private Message message_id;

    public void setMessage_id(Message message_id) {
        this.message_id = message_id;
    }

    public void setMsg_key(int msg_key) {
        this.msg_key = msg_key;
    }

    public int getMsg_key() {
        return msg_key;
    }

    public Message getMessage_id() {
        return message_id;
    }
}

As DBFlow document,

All fields must be public or package private as the _Adapter class needs access to them. NOTE: Package private fields need not be in the same package as DBFlow will generate the necessary access methods to get to them.

Or private ONLY when you specify get{Name}() and set{Name}(columnType) methods for a column named {name}. This can be configured.

But when I build the application, android studio throw an error that

Error: incomparable types: int and <null>

Then I check generated code by DBFlow and realize its compare int with null.

enter image description here

I'm not sure it's DBFlow bug or I missing/wrong configuration on somewhere? Please give me your suggest/solutions.

Thanks!

============= Update =============

I'm using DBFlow 3.0.0 beta3

0

There are 0 best solutions below