我想我最终为我的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
关于这个的两个问题: