Ormlite - Constructor call failing when BaseDaoImpl is extended

后端 未结 1 1275
轮回少年
轮回少年 2021-01-13 13:27

I have the following tables -

@DatabaseTable(tableName=\"b\", daoClass=B_DaoImpl.class)
public class B {

   @DatabaseField
   public String b1 ;

   public         


        
1条回答
  •  星月不相逢
    2021-01-13 14:04

    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:

    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)
      ...
    

    Because A has a foreign field of class B, then B needs to have an id field. Identity fields are required for foreign fields.

    I'm sure A and B are 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.

    0 讨论(0)
提交回复
热议问题