Android ORM / JPABy Roger Keays, 19 December 2011, 6:01 AM |

Coming from the server-side, I find it hard to live without ORM (Object-Relational Mapping) such as JPA. Now that I've started writing Android Apps, I set about finding a JPA ORM tool for Android.
Here is a comparison of the tools I found that do ORM and are lightweight enough for use with Android.
| Annotations | DB Ops | Size | License | Docs | Age | |
|---|---|---|---|---|---|---|
| OrmLite | JPA or custom | DAO or Entity | 200kb | Open | docs | 1yr |
| ORMAN | JPA-like | Entity | 170kb | Apache2 | wiki | 2yrs |
| greenDAO | N/A Codegen | DAO or Entity | <100kb | Apache2 | docs | |
| ActiveAndroid | JPA-like | Entity | $20 | wiki | ||
| AndrORM | None | docs | 1yr |
"DB Ops" refers to how database operations such as persist() and update() are handled. Normally either by a DAO (data access object) or by the entity themselves.
Performance counts - especially since I need to handle large data sets. I don't want to load 3000 records into memory at once when the device only has room to display 10 at a time. Native Android supplies a Cursor to interate large data sets, and some ORM tools provide their own method too.
greenDAO has Query.lazyList() and OrmLite has DAO.iterator(Query) to do this, however Android adapters do not bind to an iterator so a custom adapter would need to be written in any case. There is a thread online that discusses this, however I think I can rig up a something similar to my LazyList for JPA to make this happen.
I've started my project with OrmLite because it is the most mature. Lazy loading query results will need some custom code, but in the long run I think it will be better than polluting my code with column names and SQL hacks.
greenDAO was a good candidate from the performance perspective, but really I want to write my Entities myself so I can add the methods that I need.
Android ORM / JPA![]() |
Roger is an active member of the JSF 2 Expert Group and is happy to be a contributor to the Java Community. He has been writing software since the age of 8 and his other interests include languages, science, travel and surfing. You can follow Roger on Twitter and Google+. |
| « How To Move A Node In Nested Sets With SQL | Back to Blog | Alt-Tab Shortcuts Broken In Ubuntu Lucid With XModMap » |