Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7810535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:49:06+00:00 2026-06-02T03:49:06+00:00

I have the following tables – @DatabaseTable(tableName=b, daoClass=B_DaoImpl.class) public class B { @DatabaseField public

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:49:07+00:00Added an answer on June 2, 2026 at 3:49 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables: Table A: id int v1 string v2 string Table
I have the following tables structure: Shipment (has IDDestination as foreign key) -> Destination
I have the following 2 tables defined in migrations class CreateUsers < ActiveRecord::Migration def
I have the following tables Pedal Brand:string Classification:string Model:string Variety Title:string name:string pedal_id:integer Example
I have following tables questions -> id, question_data, user_id users -> id, fname, lname
I have the following tables: Universities( iduni, uniname ) Campuses( idcampus, iduni, campusname, campusaddress
I have the following tables: FACULTY table CREATE TABLE FACULTY ( FACULTY_ID NUMBER(3,0), FACULTY_NAME
I have the following tables --subscribers-- id name e-mail --categories-- id subscriber_id cat1 cat2
I have the following tables used for sending messages about products to vendors from
I have the following tables: DataValue DateStamp ItemId Value ---------- ------ ----- 2012-05-22 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.