GreenDao不创造外键吗?

时间:2017-03-12 00:47:19

标签: java android sqlite foreign-keys greendao

我刚刚开始学习这个ORM,所以也许我做错了什么。在实体中我写了OneToOne关系但是greendao没有生成它。如果我在实体构造函数参数中写入外键,它就会忽略它并使它像这样。因此表中没有属性和列。谢谢。

公开:

@Entity(active = true)
public class Public {

@Id(autoincrement = true)
Long id;

int publicId;

@ToOne(joinProperty = "id")
private Category category;  ...

@Generated(hash = 12945501)
public Public(Long id, int publicId) {
    this.id = id;
    this.publicId = publicId;
}

PublicDao:

public class PublicDao extends AbstractDao<Public, Long> {

public static final String TABLENAME = "PUBLIC";

/**
 * Properties of entity Public.<br/>
 * Can be used for QueryBuilder and for referencing column names.
 */
public static class Properties {
    public final static Property Id = new Property(0, Long.class, "id", true, "_id");
    public final static Property PublicId = new Property(1, int.class, "publicId", false, "PUBLIC_ID");
}    ...

/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
    String constraint = ifNotExists? "IF NOT EXISTS ": "";
    db.execSQL("CREATE TABLE " + constraint + "\"PUBLIC\" (" + //
            "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
            "\"PUBLIC_ID\" INTEGER NOT NULL );"); // 1: publicId
}

1 个答案:

答案 0 :(得分:0)

我的错误。我应该为它添加另一个字段,并将其写入joinProperty。