greenDAO 1.3 Release

Multithreading and Maven/Gradle support are the two major themes of greenDAO 1.3. If you are using greenDAO from multiple threads, you are highly advised to upgrade to the latest version of greenDAO to prevent deadlocks. Fixing these issues led to small modification to Queries resulting in breaking changes that require small adjustments in your code. We seized this opportunity to refactor code and introduce a couple of new packages. There are a few actions required to upgrade on your side, see below for a list.

The second major change is using Gradle to build greenDAO, and more importantly, to push artifacts to Maven Central. This is now the primary location to get greenDAO (GitHub discontinued downloads anyway). So add dependencies to group ID “de.greenrobot” with the artifact IDs greendao and greendao-generator to add greenDAO to your project. If you don’t use Maven or Gradle, please download the jars directly from Maven Central.

Required actions to upgrade to greenDAO 1.3:

  1. Upgrade the greenDAO generator jar and completely regenerate code
  2. Upgrade the greenDAO jar in your Android project
  3. Fix the import statements; e.g. QueryBuilder and Query are now in de.greenrobot.dao.query
  4. Call forCurrentThread() before using a cached Query object and consider removing synchronized statements around the query. For details, please read the section “Executing queries in multiple threads” in the Queries documentation.

And finally, here is the greenDAO 1.3 change log:

  • Reworked internal locking of insert/update/delete methods
  • Fixed potential deadlocks when transactions are executed concurrently to one of the various insert/update/delete calls
  • Reworked queries to be used without locking, query instances are now bound to their owner thread (breaking change!)
  • Relations use the new lock-free query API
  • Query classes were moved into the new query subpackage (breaking change!)
  • Introduced Gradle build scripts for DaoCore and DaoGenerator projects
  • Maven artifacts are pushed to Maven Central starting with this version
  • Added two packages for classes used internally (identityscope and internal)
  • Added new deleteByKeyInTx DAO method to efficiently delete multiple entities using their keys
  • Added some checks to throw exceptions with nicer messages telling what’s wrong
  • Added Travis CI
Spread the love
Posted in Release and tagged , , , , , , , .


  1. Since you now support maven, do you plan to update your sample project with maven integration?

  2. My plan would be to update the sample with a real Gradle script, once the Android build system is ready for that. But a Mavenized sample might be a good idea, too…

  3. it seems like there’s no download to the jar in the download page, and no freemaker.jar in the source, how am I supposed to upgrade my DB?

    should I got through all the generated code and manually change everything?

  4. Hi, this is obviously not the place but I don’t feel this is a StackOverflow question. Could you update the sessions documentation on how to share a session between threads?

    This is what I’m using

    public class MHGreenDao {
    private static volatile DaoSession mDaoSession;

    private MHGreenDao(){}

    public static DaoSession getDaoSession(Context context){
    if(mDaoSession == null){
    synchronized (MHGreenDao.class) {
    if(mDaoSession == null){
    DevOpenHelper helper = new DaoMaster.DevOpenHelper(context.getApplicationContext(), AppConfig.DATABASE_NAME, null);

    mDaoSession = new DaoMaster(helper.getWritableDatabase()).newSession();

    return mDaoSession;

    I’ve fixed some “session not closed” messages, but I’d like to know if there’s a better way. I’ve seen you propose the use of singleton in previous posts.

  5. Thanks everyone for feedback!

    @Yishai No need to update your database. You must regenerate the greenDAO code using the newest version.

    @Maragues: It looks good for using in apps. The problem with singletons is unit testing however. To have a fresh state for each unit test, you should either take care of it yourself or store the DaoSession in Application-scope.

    @Yishai & Zaho: just got updated to reference greenDAO’s Maven repositories.

  6. We used your library in one of our projects and really enjoyed it.
    But we have to build an extension on top of your library to allow get us pure Cursor. It is not very effective to make a query and hold a lot of objects in memory, while ListView can do it more effective via Cursor.
    Do you plan to have an alternative APIs for Query classes to expose Cursor and not only lists?

  7. Hi.

    just went into the page again (since I’m restructuring the DB) and freemaker.jar is still not there.

    For now, I’ll use the old one I have from version 2.0…

Comments are closed.