60

Which is the best ORM tool available for Android?

I am seeing ORMlite and ActiveAndroid are the most discussed across and a friend of mine suggested me to use GreenDAO. So looking for some knowledge resource which can help me in Decision Making?

Features I am looking to judge are freely available (open source), good documentation, active forums, stable version available, etc, which ever required for developer.

yanchenko
  • 56,576
  • 33
  • 147
  • 165
Ravi G
  • 859
  • 1
  • 8
  • 21
  • 4
    GreenDao is simple to use but it has its limit, for Ex. One cannot configure the cache, contrary to ORMLite's cache and is not a "Real" ORM. I'll explain my answer, in ORMLite you can configure the cache in some manner that queries might not need to access the database, in GreenDao it's not possible and every query pointed to the database – Nativ May 20 '13 at 18:07
  • thank you for asking this question – necromancer Aug 30 '14 at 01:09
  • Another factor to think about is Android architecture. ORMLite makes you extend an activity, which may not work with some architectures. – stevebot Mar 30 '15 at 05:20
  • @stevebot, no, I don't need to extend an Activity when you use ORMLite – cVoronin Nov 11 '15 at 07:17

3 Answers3

23

I would suggest ORMlite its open source freeware & has good documentation also it support java as well as android.

It has good developer support & many application running on ORMlite (Including I have developed :) ).

check this comparison of ORMLite & Green DAO for your referance.

R World
  • 766
  • 9
  • 26
  • 2
    Thanks for responding, but in that comparison I don't see any major difference ORMLite and GreenDAO. I am able to find GreenDAO performs better, but ORMLite is popular. Still trying to know which makes ORMLite more popular than the one which performs well. – Ravi G Dec 03 '12 at 13:02
  • 1
    Adding links to support above comments http://stackoverflow.com/questions/11537561/which-java-orm-is-suitable-for-android-os-and-support-lazy-list http://greendao-orm.com/features/ – Ravi G Dec 03 '12 at 13:11
  • 4
    Regarding the comparison... I don't understand the use of JAR file size as a measure of library 'weight'. One library might have lots of extra optional functionality that gets stripped out in most projects. I think it would be necessary to build a basic project of each and check APK size deltas for release builds. – Tom Mar 30 '13 at 20:10
  • Is there also a benchmark comparison of other libraries, like SugarOrm ? – android developer Feb 20 '14 at 11:41
  • 6
    I found this post a year or two ago while looking for a good ORM for Android, and this lead me to use ORMLite for a time, which I regret. ORMLite just really isn't written well for Android though. If you look at benchmarks it is several orders of magnitude slower than other ORMs like GreenDAO even on the latest Android OS. This is because ORMLite heavily relies on reflection for everything, and is so slow because it creates so many objects that need to be GC'd. GC in Android = laggy UI. I'd recommend investing time in a different ORM. – spierce7 Sep 12 '14 at 03:20
  • I am curious about how the comparison changes with ART. @spierce7 mentioned GC time, and that is the whole point of the ART runtime. Anyone who knows/will do a benchmark? – doplumi Oct 16 '14 at 14:40
  • @domenicop I imagine the tests won't have as drastic a difference on ART, but for a few more years most users still won't be on ART, I'd argue GreenDAO is still your best bet. Don't get me wrong, GreenDAO has disadvantages (not supporting enums, not supporting annotations. People have put in pull requests to add these features, but they still haven't merged them). Still, GreenDAO is fast, and pretty simple when you get right down to it. It's my go to DB for now and at least the next few years. – spierce7 Nov 24 '14 at 01:24
11

A difference between ORMLite and GreenDAO is the usage of annotations. While ORMLite uses Annotations, GreenDAO does not, as described here.

Annotations used by ORMLite rely on reflection, which might impact performance especially on slower Android devices in a negative way. Would be interesting to see benchmarks comparing ORMLite and GreenDAO.

Philipp
  • 788
  • 1
  • 11
  • 23
  • 16
    ORMLite on Android can use a compile-time generated config file that avoids relying on reflection altogether during app usage. Using annotations is important to me as you can use existing model objects. – Rafael Nobre Jul 23 '13 at 16:35
  • 1
    Here you have a Github project that compares the performance of ORMLite and GreenDao to raw SQLite: https://github.com/littleinc/android-orm-benchmark – Diego Palomar Nov 26 '14 at 16:51
  • 1
    Annotations DON'T rely on reflection. Libraries using Annotations MAY rely on reflection. AndroidAnnotations, Dagger 2, Retrofit, ButterKnife, LoganSquare, Gson, Wire, etc are examples of libraries using Annotation Processor, which generate boilerplate code at compile time, and don't use reflection at all – Louis CAD Nov 20 '15 at 18:45
  • The annotations used by ORMLite were meant in this case, not annotations in general. I will update the answer to make this more explicit. – Philipp Jan 29 '16 at 12:30
  • For people who got here via Google: This information is outdated, GreenDAO supports annotations since version 3 which was released in July 2016. – TiEul Nov 23 '16 at 10:36
5

One issue I have with a number of the libraries that I've used is that they require that their initialization take place in android.app.Application.onCreate(). I prefer that libraries allow me to do their initialization in a secondary thread, in a service, or after I have finished displaying the user interface.

I believe that Active Android has this 'problem', and ORMLite does not. I'm not sure about GreenDAO.

Whether it is really a problem depends on your application, but I will note that the docs for onCreate() say "Implementations should be as quick as possible (for example using lazy initialization of state) since the time spent in this function directly impacts the performance of starting the first activity, service, or receiver in a process."

Unrelated to that, I note that ActiveAndroid uses annotations, like ORMlite, but unlike GreenDAO which uses code generation.

Tom
  • 17,103
  • 8
  • 67
  • 75
  • Sugar ORM, considerably light, on the other hand does not pose this problem. You can do things from inside services if you want. – C-- Aug 04 '15 at 11:49
  • [JDXA](http://www.softwaretree.com/2015/products/jdxa/jdxa.html) ORM for Android gives the flexibility of initialization at anytime in your application life cycle. JDXA follows the [KISS Principles](http://www.softwaretree.com/2015/KISSPrinciples.html) of ORM. JDXA does not use annotations. It is totally non-intrusive to your domain object model - there is no need to subclass from any base class; no need for DAO classes. – Damodar Periwal Oct 21 '15 at 05:08
  • @DamodarPeriwal I have to fill out a form to obtain it? No thank you – TheRealChx101 Aug 14 '19 at 00:10