使用JSONModel的DBFlow抛出InvalidDB配置:JSONModel未向数据库注册

时间:2015-02-17 12:21:34

标签: android orm

我开始使用DBFlow并遵循文档。我有一个巨大的JSON,我不想上传所有内存,所以我使用他们实施的JSONModel方法。

    admissionJSONModel = new JSONModel<Admission>(jsonObject, Admission.class);

录取班:

@Table(databaseName = AppDatabase.NAME)
@ContainerAdapter
public class Admission extends BaseModel {

  /**
   * Ticket Reference (barcode number)
   */
  @NonNull
  @ContainerKey("TICKET_REF")
  @Column(columnType = Column.PRIMARY_KEY)
  String mTicketReference;

  @NonNull
  @Column
  @ContainerKey("FIRST_NAME")
  String mFirstName;

  /**
   * Ticket type (related to Record type)
   * In ADDRESS_CITY
   */
  @Column
  @ContainerKey("TICKET_TYPE")
  int mTicketType;


                ...
}

Ant数据库类:

@Database(name = AppDatabase.NAME, version = AppDatabase.VERSION, foreignKeysSupported = true)
public class AppDatabase {

    public static final String NAME = "App";

    public static final int VERSION = 1;
}

我拥有的异常的堆栈跟踪是:

Process: com.glownet.app.staging.debug, PID: 19083
    java.lang.RuntimeException: com.raizlabs.android.dbflow.structure.InvalidDBConfiguration: Table: com.raizlabs.android.dbflow.structure.container.JSONModel is not registered with a Database. Did you forget the @Table annotation?
            at com.raizlabs.android.dbflow.runtime.DBTransactionQueue.run(DBTransactionQueue.java:77)
     Caused by: com.raizlabs.android.dbflow.structure.InvalidDBConfiguration: Table: com.raizlabs.android.dbflow.structure.container.JSONModel is not registered with a Database. Did you forget the @Table annotation?
            at com.raizlabs.android.dbflow.config.FlowManager.getDatabaseForTable(FlowManager.java:63)
            at com.raizlabs.android.dbflow.runtime.transaction.process.ProcessModelHelper.process(ProcessModelHelper.java:26)
            at com.raizlabs.android.dbflow.runtime.transaction.process.ProcessModelTransaction.onExecute(ProcessModelTransaction.java:34)
            at com.raizlabs.android.dbflow.runtime.transaction.process.ProcessModelTransaction.onExecute(ProcessModelTransaction.java:12)
            at com.raizlabs.android.dbflow.runtime.DBTransactionQueue.run(DBTransactionQueue.java:63)

提前非常感谢你:)

2 个答案:

答案 0 :(得分:1)

来自作者, 如果您使用的是ProcessModelTransaction,则应更改代码以将JSONModel保存到数据库,如下所示:

TransactionManager.getInstance().addTransaction(new ProcessModelTransaction<>(ProcessModelInfo.withModels(models).table(Admission.class);

目前这是一个方法table()不存在的错误。所以会发生什么呢?它认为JSONModel是一个表(因为它们实现了模型),但它们只是真实模型的shell,blueprint类。

感谢您找到这个。如果您可以在github上打开一个问题,我可以将您标记为贡献者。谢谢。

答案 1 :(得分:0)

现在,从版本1.6.1开始,它现在检测到模型为ModelContainer,并将获取要使用的相应表。