当我尝试扩展ORMLite的BaseDaoImpl时获得异常

时间:2017-07-19 19:09:52

标签: android dao ormlite

我想我最终为我的Android应用程序找到了一个不错的ORM框架。 Ormlite 5.0 易于学习且效果很好。然而,今天我在尝试通过扩展BaseDaoImpl来定义我自己的DAO类时遇到了一个问题(每次我在父表上执行某些操作时,我需要在子表上执行一些任务)。这是我的DAO课程:

public class MyEntityDAO extends BaseDaoImpl<MyEntity, Integer> {

    public MyEntityDAO(Class<MyEntity> dataClass) throws SQLException{
        super(dataClass);
        this.initialize();
    }

    public MyEntityDAO(ConnectionSource connectionSource, Class<MyEntity> dataClass) throws SQLException {
        super(connectionSource, dataClass);
        this.initialize();
    }

    public MyEntityDAO(ConnectionSource connectionSource, DatabaseTableConfig<MyEntity> tableConfig) throws SQLException {
        super(connectionSource, tableConfig);
        this.initialize();
    }

    @Override
    public Dao.CreateOrUpdateStatus createOrUpdate(MyEntity entity) throws SQLException {
        DBHelper.getHelper(MyApp.getContext()).getChildDAO().createOrUpdate(entity.getChild());

        return super.createOrUpdate(entity);
    }

    @Override
    public int delete(MyEntity entity) throws SQLException{
        DeleteBuilder deleteBuilder = DBHelper.getHelper(MyApp.getContext()).getChildDAO().deleteBuilder();
        deleteBuilder.where().eq(ChildTable.ID, entity.getChild().getId()).prepare();
        deleteBuilder.delete();

        return super.delete(entity);
    }
}

以下是MyEntity类的定义:

@DatabaseTable(tableName = "MY_ENTITY", daoClass = MyEntityDAO.class)
public class MyEntity implements Serializable {
    ....
}

我认为我做得很好,但每次尝试运行应用程序时,都会收到错误:

Could not call the constructor in class class [package name].MyEntityDAO

关于这个的两个问题:

  1. 我错过了什么或做错了什么?
  2. 在overriden方法中使用上下文是否正常,或者我应该从其他任何地方获取上下文?

0 个答案:

没有答案