Android ORM / JPA

By , 19 December 2011, 6:01 AM

Android ORM / JPA
Android ORM / JPA

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.

Handling Large Data Sets

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.

Verdict

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

About Roger Keays

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+.

Comment posted by: Sven Meier, last year

<shameless plug>

Take a look at:

   https://github.com/svenmeier/propoid

Age < 1 month, but it cursor-backed queries can easily be used with listviews.

</shameless plug>

Comment posted by: Phil, last year

 Hey, what was the reason to decide against androrm? I'm the developer and very interested in any feedback, that could help me to improve androrm. By the way it is licensed under the MIT License. See androrm.com/download/license

Comment posted by: , last year

Hi Phil. OrmLite is better documented than Androrm and seems to have a bigger community. That's all.

Comment posted by: Jeff Bethune, last year

 Were you able to get the JPA annotations working with Ormlite on Android?  Or did you go with the ormlite annotations?

Comment posted by: , last year

Jeff, the JPA annotations didn't have very good coverage of the ORMlite mappings and features and didn't offer much advantage over the native annotations so I used the native annotations.

Add a comment

Please visit http://www.NinthAvenue.com.au/android-orm-jpa to add your comments.

Follow Ninth Avenue

Get Results With Women

Website Updates


Toner

Join The Mailing List

Subscribe to our mailing list for the latest news and announcements.

Follow Us On Twitter