I am using ormlite for sqlite database in my android application. It's a login based application and I have database in SD card. For user abc, the requirement is when user login with different user like xyz then application authenticate the user from the server and server replace the db for user xyz. But when I am trying to access the login credentials it is giving the old credentials while the database is reflecting the new credentials.
I also tried:
DaoManager.clearCache();
It is not working also I tried:
DatabaseManager<DatabaseHelper> manager = new DatabaseManager<DatabaseHelper>();
manager.releaseHelper(DatabaseHelperGenerator.getDataBaseHelperInstance())
After this when I tried to fire this query:
Dao<LoginAuthentication, Integer> loginAuthenticationDao = null;
DatabaseHelperGenerator.getDataBaseHelperInstan开发者_如何学Cce().
clearLoginDao(LoginAuthentication.class);
loginAuthenticationDao = DatabaseHelperGenerator.getDataBaseHelperInstance().
getUserDao(LoginAuthentication.class);
List<LoginAuthentication> loginAuthenticationList =
loginAuthenticationDao.queryForAll();
It is giving IllegalStateException :Database not open
Looking for help.
Seems to me that you are going in the wrong direction here.
- You are assuming that the DAO is caching objects for you but unless you have enabled an object cache on a particular DAO then that's not the case.
- DaoManager.clearCache() doesn't clear object caches but instead clears the cached DAO objects.
- Once you release the helper, the database connection is closed which is the reason why you are getting the
IllegalStateException
.
I'd do some debugging of your application or some logging of values to see where the problem lies. Here are some thoughts:
- If you are using an object cache, have you tried to disable it? Have you tried flushing the object cache by calling Dao.clearObjectCache()? Again, a cache will only exist if you have turned it on. It is not on by default.
- What code are you using to persist the login information? Anything different than other calls?
- How about using the Dao.queryRaw() methods to dump the database right after the insert?
- Any transactions?
Best of luck.
精彩评论