2012-04-17 23 views
4

を拡張した場合、私は次のテーブルがある -Ormlite - コンストラクタ呼び出し失敗BaseDaoImplが

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); 
    } 
} 

データベースヘルパーは次のようにこれらのテーブルの

@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 
    } 
} 

を、関連するダオとDaoImplは、次のとおりです。今

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; 
    } 
} 

、私が呼び出すしよう -

次のエラーとの
ADao aDao = databaseHelper.getA(); 

そのエラーアウト:

Could not call the constructor in class class A_DaoImpl 

、私は中foriegnキーがない場合、 - Aが公衆BのBが含まれていない場合、すなわち、それが正常に動作します。私がここで紛失しているものがありますか?

ありがとうございます。

+0

例外をすべて転記できますか?その例外の原因情報があるはずですか?また、ORMLiteのどのバージョンを使用していますか? – Gray

+0

ええ、それは貢献と最高の答えについての "正しい"についてではありません。良い答えがない場合は、自分で答える必要があります。 – Gray

+0

私は最高の答え:)グレイありがとうございます。 – Koran

答えて

5

例外スタックトレースの最後に欠落しているというメッセージが表示されると思われます。私は上記のあなたの例を複製たとえば、私が取得:

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

AがクラスBの外国分野を持っているので、その後、Bは、idフィールドを持っている必要があります。外部フィールドにはIDフィールドが必要です。

ABは単純なバージョンのクラスなので、すべての原因情報を含めてさらに例外を投稿すると、適切に回答が編集されます。

+1

グレイありがとう。それは確かに問題でした。私はこの答えを探している間にもこの問題を見ていましたが、私がDaoImplを全部持っていたので、私は横たわってしまいました。ありがとうございました。あなたは大きな助けになった。 – Koran

関連する問題