gpt4 book ai didi

java - GreenDao 不创建外键?

转载 作者:太空宇宙 更新时间:2023-11-04 11:41:20 25 4
gpt4 key购买 nike

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

公共(public)道:

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
}

最佳答案

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

关于java - GreenDao 不创建外键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42742439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com