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 7522395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:30:36+00:00 2026-05-30T02:30:36+00:00

So I have a custom subclass of OrmLiteSqliteOpenHelper . I want to use the

  • 0

So I have a custom subclass of OrmLiteSqliteOpenHelper. I want to use the ObjectCache interface to make sure I have identity-mapping from DB rows to in-memory objects, so I override getDao(...) as:

@Override
public <D extends Dao<T, ?>, T> D getDao(Class<T> arg0) throws SQLException {
    D dao = super.getDao(arg0);
    if (dao.getObjectCache() == null && !UNCACHED_CLASSES.contains(arg0))   
        dao.setObjectCache(InsightOpenHelperManager.sharedCache());
    return dao;
}

My understanding is that super.getDao(Class<T> clazz) is basically doing a call to DaoManager.createDao(this.getConnectionSource(),clazz) behind the scenes, which should find a cached DAO if one exists. However…

final DatabaseHelper helpy = CustomOpenHelperManager.getHelper(StoreDatabaseHelper.class);

final CoreDao<Store, Integer> storeDao = helpy.getDao(Store.class);
DaoManager.registerDao(helpy.getConnectionSource(), storeDao);
final Dao<Store,Integer> testDao = DaoManager.createDao(helpy.getConnectionSource(), Store.class);

I would expect that (even w/o the registerDao(...) call) storeDao and testDao should be references to the same object. I see this in the Eclipse debugger, however:

Different object IDs

Also, testDao‘s object cache is null.

Am I doing something wrong here? Is this a bug?

I do have a custom helper manager, but only because I needed to manage several databases. It’s just a hashmap of Class<? extends DatabaseHelper> keys to instances.

The reason I need my DAO cached is that I have several foreign collections that are eager and are being loaded by internally-generated DAOs that are not using my global cache and thus are being re-created independently for each collection.

As I was writing this up, I thought I could just have my overridden helpy.getDao(...) call through to DaoManager.createDao(...), but that results in the same thing: I still get a different DAO on the second call to createDao(...). This seems to me to be totally against the docs for DaoManager.

First, I thought it looked like registerDao(...) may be the culprit:

public static synchronized void registerDao(ConnectionSource connectionSource, Dao<?, ?> dao) {
        if (connectionSource == null) {
            throw new IllegalArgumentException("connectionSource argument cannot be null");
        }
        if (dao instanceof BaseDaoImpl) {
            DatabaseTableConfig<?> tableConfig = ((BaseDaoImpl<?, ?>) dao).getTableConfig();
            if (tableConfig != null) {
                tableMap.put(new TableConfigConnectionSource(connectionSource, tableConfig), dao);
                return;
            }
        }
        classMap.put(new ClassConnectionSource(connectionSource, dao.getDataClass()), dao);
    }

That return on line 230 of the source for DaoManager prevents the classMap from being updated (since I’m using the pregenerated config files?). When my code hits the second create call, it looks at the classMap first, and somehow (against my better understanding) finds a different copy of the DAO living there. Which is super weird, because stepping through the first create, I watched the classMap be initialized.

But where would a second DAO possibly come from?

Looking forward to Gray’s insight! 🙂

  • 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-05-30T02:30:38+00:00Added an answer on May 30, 2026 at 2:30 am

    As @Ben mentioned, there is some internal DAO creation which is screwing things up but I think he may have uncovered a bug.

    Under Android, ORMLite tries to use some magic reflection to build the DAOs given the horrible reflection performance under all but the most recent Android OS versions. Whenever the user asks for the DAO for class Store (for example), the magic reflection fu is creating one DAO but internally it is using another one. I’ve created the follow bug:

    https://sourceforge.net/tracker/?func=detail&aid=3487674&group_id=297653&atid=1255989

    I changed the way the DAOs get created to do a better job of using the reflection output. The changes were pushed out in the 4.34. This release revamps (and simplifies) the internal DAO creation and caching. It should fix the issue.

    http://ormlite.com/releases/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom NSActionCell subclass, and I want to use setTarget: message to
I have a custom UIView subclass that i'm trying to use as a header
What I want to do I have a circular custom NSView subclass, and I
I have a custom NSView subclass that I want to animate with Core Animation.
I have created a custom subclass of UIView for an interface element that I
I have a custom UIView subclass without a corresponding UIViewController. I use this class
I have a custom UIViewController subclass and I want to override the loadView method.
I have a custom UITableViewCell subclass, and a table view controller which I want
Similar to this question I have a custom subclass of UITableViewCell that has a
I have created a custom subclass of UITableViewCell. There, I allow the user to

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.