android - ORMLite 中是否继承了 ID 字段?

标签 android ormlite

假设我有以下类(class):

public abstract class AHuman
{
    @DatabaseField(id = true)
    protected String login;
}

下面的两个类扩展了它:

@DatabaseTable(daoClass = UserDAO.class)
public class User extends AHuman
{
     User() {}

     @ForeignCollectionField
     private ForeignCollection<Person> friends;
}


@DatabaseTable(daoClass = PersonDAO.class)
public class Person extends AHuman
{
    Person() {}
}

当我在我的 Android 设备上编译并运行它时,出现以下错误:

java.sql.SQLException: Could not call the constructor in class class 
      com.j256.ormlite.table.CustomDaoTest$A_DaoImpl
  at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
  ...
Caused by: java.lang.reflect.InvocationTargetException
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  ...
Caused by: java.lang.IllegalArgumentException: Foreign field class
>>>>      com.j256.ormlite.table.CustomDaoTest$B does not have id field  <<<<<<
  at com.j256.ormlite.field.FieldType.configDaoInformation(FieldType.java:332)

此错误源自 ForeignCollection<Person>User 中声明类。

显然,来自以下问题 here ,这是因为 Person 类没有在其中声明的“id”字段。

但是从抽象类继承的“id”字段不也包含在子对象中吗?

最佳答案

@Id 字段是继承的。也许问题在于您的构造函数不是公共(public)的(使用默认说明符)

关于android - ORMLite 中是否继承了 ID 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25846498/

相关文章:

java - 将 Dao 作为静态成员存储在类中是否安全?

android - 如何在原始查询中正确定义 SelectArg?

android - Gradle 应用程序变体 mergeAssets 不工作

android - 如何在 flutter 中打开位置后更新我的位置

android - 使用 OpenGL 和 MediaCodec 播放视频

foreign-keys - 为什么没有foreignAutoDelete?

android - OrmLiteConfigUtil 配置文件生成问题

java - Android- Dexopt 错误

java - 如何将数组中的项目放入不同的复选框中?

android - 使用 ORMLITE 在 Android 中的多个查询条件