【问题标题】:GreenDao doesn't create foreign key?GreenDao 不创建外键?
【发布时间】:2017-03-13 09:54:46
【问题描述】:

我刚刚开始学习这个 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
}

【问题讨论】:

    标签: java android sqlite foreign-keys greendao


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-10
      相关资源
      最近更新 更多