I have the following tables –
@DatabaseTable(tableName="b", daoClass=B_DaoImpl.class)
public class B {
@DatabaseField
public String b1 ;
public B(){
// For Ormlite
}
}
@DatabaseTable(tableName="a", daoClass=A_DaoImpl.class)
public class A {
@DatabaseField
public String a1 ;
@DatabaseField(foreign=true)
public B b;
public A(){
// For Ormlite
}
}
For these tables, the associated Dao and DaoImpl are as follows
public interface A_Dao extends Dao<A, String>{}
public interface B_Dao extends Dao<B, String>{}
public class B_DaoImpl extends BaseDaoImpl<User, String> implements B_Dao {
public B_DaoImpl(ConnectionSource connectionSource) throws SQLException {
super(connectionSource, B.class);
}
}
public class A_DaoImpl extends BaseDaoImpl<User, String> implements A_Dao {
public A_DaoImpl(ConnectionSource connectionSource) throws SQLException {
super(connectionSource, A.class);
}
}
Database helper is as follows:
public class DatabaseHelperImpl extends OrmLiteSqliteOpenHelper implements DatabaseHelper {
private A_DaoImpl aDao = null;
private B_DaoImpl bDao = null;
public B_DaoImpl getBDao() throws SQLException {
if (bDao == null) {
bDao = getDao(B.class);
}
return bDao;
}
public A_DaoImpl getA() throws SQLException {
if (aDao == null ) {
aDao = getDao(A.class);
}
return aDao;
}
}
Now, when I try to call –
ADao aDao = databaseHelper.getA();
it errors out with the following error:
Could not call the constructor in class class A_DaoImpl
Now, if I do not have the foriegn key in A – ie if A does not contain public B b, it works fine. Is there something that I am missing here?
Thank you very much in advance.
I suspect that there is cause message you are missing at the end of your exception stack trace. For example, if I duplicate your example above I get:
Because
Ahas a foreign field of classB, thenBneeds to have an id field. Identity fields are required for foreign fields.I’m sure
AandBare simplistic versions of your classes so if you post more of the exception including all of the cause information, I’ll edit my answer appropriately.