291

Anyone working on the Android ('gPhone') have or know of a place where I can find a good ORM tool for it? The code is written in Java, and the database is SQLite. What I would like to find is a tool that given the object definition, can auto-generate the tables and the CRUD functions (that would be awesome), or, barring that, a tool that can take the table definition, the object definition, and auto-generate the CRUD functionality. The rub is that all of this must happen within the Android framework, which has its own conventions as to how database access works.

JJD
  • 50,076
  • 60
  • 203
  • 339
GWLlosa
  • 23,995
  • 17
  • 79
  • 116
  • I don't think there are any available now. – mparaz Feb 17 '09 at 10:36
  • 2
    its 2014. I thought I will mention Sprinkles (https://github.com/emilsjolander/sprinkles) since no one has mentioned it.. 500 stars on github, on meaven central, content observers, worth checking – AndroidGecko Apr 10 '14 at 12:43
  • It's 2015. Software Tree has recently released [JDXA](http://www.softwaretree.com), a simple yet powerful, and flexible ORM for Android. Supports inheritance, one to one, one to many, many to one, and many to many relationships. JDXA's POJO (Plain Old Java Objects) friendly non-intrusive programming model does not require you to change your Java classes in any way: - No need to subclass your domain classes from any base class - No need to clutter your source code with annotations - No need for DAO classes - No source code generation – Damodar Periwal Sep 30 '15 at 01:12
  • Check out this nice **[tutorial on JDXA ORM](https://onelonecoder.wordpress.com/2015/11/02/jdxa-simple-but-powerful-orm-library-for-android/)**. – Damodar Periwal Nov 13 '15 at 22:35
  • If you prefer plain natural Android code without additional library dependencies take a look at the [SQLite peer class code generator example](http://uc-mobileapps.com/android-code-generator/example-1/one-many-relation/). It is annotation based and supports combined primary keys, combined unique constraints and indexing. – RookieGuy Apr 27 '17 at 08:48

15 Answers15

112

Thought I'd just add my $0.02 here about my ORMLite package.

It is a lightweight replacement to Hibernate and uses native Android OS database calls to support SQLite on Android. It also supports many other database types using JDBC on other architectures. We have an Android mailing list for ORMLite questions.

Gray
  • 115,027
  • 24
  • 293
  • 354
  • 1
    Does ORMLite have built-in support for (one|many)-to-(many|one) relationships? I can't find much info on that ... If not, are there plans for this? – ferdystschenko Feb 22 '11 at 06:35
  • 1
    Depends on what you mean by "support". There is some example code on how to use "foreign objects" which are how you to one-to-many and there are examples on how to use join tables to accomplish many-to-many (http://ormlite.com/docs/examples). Post to the user list with more questions (http://groups.google.com/group/ormlite-user/). – Gray Feb 23 '11 at 15:06
  • It looks good however jar size is in excess of 200K vs. 18K for ActiveAndroid. I'm not sticking anything in my app no matter how good it is which adds 40% to its size – Bostone Apr 02 '11 at 19:27
  • 7
    Yeah, it is certainly larger than ActiveAndroid. A lot more functionality as well of course. Also freeware as opposed to AA's license. But if size is the goal, ORMLite is not for you. – Gray Apr 02 '11 at 19:54
  • 4
    @Gray Ironic since it's supposed to be "Lite" :P – Samuel Katz Feb 23 '13 at 06:05
  • 5
    Indeed @SalmanPK. Although there are varying degrees of lite. :-) – Gray Feb 23 '13 at 13:25
  • @Gray can yo please tell me how we can IDR can be used to import ORMLite android project, i want to extend it for my project – Ando Masahashi Sep 27 '19 at 09:25
67

This question cannot age but the suggested frameworks can. So, here is first a list of what I find important in such frameworks for comparison:

  • Is there a Maven or Gradle artifact? (that's a big plus depending on whether you use maven or gradle, obviously)
  • Is the code accessible in an easy way including a fast overview on commits to judge the activity? (code hosted on github is a definite plus for me, in that matter)
  • Release management: are there releases/release tags and artifacts for it? (there are some that are hosted on github and require either git clone or offer the master tarball for download - for me a big minus if not even release tags are set and addressed in the README)
  • as size matters I put up some hints where it was easy to get by (I did not download anything, so from those projects that offer no release artifacts there are no sizes)

And here is a list of frameworks with notes on the points above. I looked up some more like aBatis and Hadi but I added only those that had some activity after 2011.

I have not tried any of those but maybe I can spare current readers a bit of time by listing the nowadays active projects. Please add a comment if you know of other projects that satisfy some of the above points and have some serious development (over some time) going on.

EDIT (2013 Nov): updated the list to the current status of the projects. Some of these have added release tags to their github repos as well as Maven/Gradle support. Good work!

EDIT (2015 Apr): updated the list, added Sprinkles (as per comment by @AndroidGecko) and Realm.io.

Risadinha
  • 16,058
  • 2
  • 88
  • 91
40

If performance and code size matter, check out greenDAO. I'm the author of it, and my motivation to create another ORM was to avoid reflection in the hotspots. It turned out that greenDAO can be up to 4 times faster than ORMLite. Checkout the feature page for details.

Markus Junginger
  • 6,950
  • 31
  • 52
  • 5
    Looks quite good, but having to generate the Dao's is a turnoff for me :( – Chris.Jenkins Dec 13 '11 at 14:56
  • 4
    Yes, generating code is an additional step for developers, but it saves you a great deal of performance in the app. Both bootstrapping and parsing database results are significantly faster. Other tools rely on reflection, which is cruelly slow in Android. – Markus Junginger Dec 14 '11 at 19:45
  • I think i jumped the gun on that one, after a revisit (not so tired). It looks nicer than the alternatives. and im defiantly all for speed! – Chris.Jenkins Dec 15 '11 at 16:33
  • 1
    I'm using greenDao in my projects, and I'm very pleased with it. – mabac Feb 22 '12 at 19:44
  • 3
    @greenrobot do you have some showcases of "big apps" using your lib? – StErMi Oct 26 '12 at 13:35
  • @greenrobot does youy lib supports many-to-many relation? Can we create virtual tables to accelearate search? Does it include all the features documented on sqlite.org for sqlite database? – Ashwin N Bhanushali Feb 26 '13 at 08:46
  • 1
    @StErMi Path is using greenDAO. They have >1 M installs. See https://github.com/greenrobot/greenDAO/issues/20#issuecomment-13278922 – Markus Junginger Feb 26 '13 at 12:27
  • Uhmmm really really interesting. Thanks @greenrobot. Actually to be honest I'm just using Gson and saving it directly into tablet. Each table has _id, json and a list of index fields (used for searches). – StErMi Feb 26 '13 at 14:01
  • 1
    Does greenDAO fetch relations via joins? We just check out OrmLite, and were surprised to see that a foreign @DatabaseField is fetched in a separate query. Worse, calling dao.queryForAll suffers from the N+1 problem; in case of 1000 items it will fetch the item, then do 1000 queries for the relation field... – mxk Mar 12 '13 at 14:15
  • 1
    To-one relationships can be resolved eagerly using a single query along with the main object. Look for loadDeep/queryDeep in http://greendao-orm.com/documentation/relations/. To-Many relations are resolved using a single query. – Markus Junginger Mar 13 '13 at 09:28
  • I think it's important to say greenDAO has a better compatibility with ProGuard than ORMLite. – Renan Ferrari May 21 '14 at 05:05
  • No supporting Many to many relationships is a big fail – fire in the hole Oct 15 '15 at 08:21
  • @Sheagorath, [JDXA ORM](http://www.softwaretree.com/v1/products/jdxa/jdxa.html) for Android easily supports complex object modeling including inheritance, one-to-one, one-to-many, and many-to-many relationships and offers a POJO (Plain Old Java Objects) friendly non-intrusive programming model, which does not require you to change your Java classes in any way: • No need to subclass your domain classes from any base class • No need to clutter your source code with annotations • No need for DAO classes • No source code generation – Damodar Periwal Nov 12 '15 at 02:09
  • 1
    @Sheagorath greenDAO 2.0 supports many-to-many – Markus Junginger Nov 13 '15 at 06:47
  • 1
    @greenrobot: yeah but its buggy and unusable, see: https://github.com/greenrobot/greenDAO/issues/249 – fire in the hole Nov 13 '15 at 12:21
10

I don't know of anything that is exactly what you are asking for, but there is an alternative to SQLite that you may find useful if your architecture requirements are flexible. It may be worth checking out db4o:

JJD
  • 50,076
  • 60
  • 203
  • 339
slf
  • 22,595
  • 11
  • 77
  • 101
9

ActiveAndroid ($20) looks like it may be exactly what you need.

Michael Pardo
  • 2,590
  • 3
  • 24
  • 33
  • 14
    I know you're not trying anything shifty here, but can you please disclose your affiliation in your posts when you mention one of your own products on SO? I know your name is in the footer of the linked page, but we're trying to crack down on [astroturfing](http://en.wikipedia.org/wiki/Astroturfing) (which this is not), so we're asking everyone to follow the same disclosure guidelines. Thanks. – Bill the Lizard Aug 25 '10 at 15:40
  • 4
    Just a heads up, ActiveAndroid is not free. – gak Oct 26 '10 at 21:52
  • 7
    ActiveAndroid is now free and open-source - http://pardom.github.com/ActiveAndroid/ – Michael Pardo Nov 17 '12 at 20:49
7

I liked ActiveAndroid. It's written specifically for Android it seems. That's feels like a plus to me.

I have some Ruby on Rails experience and if you like the Rails way of ActiveRecord you can very quickly get moving with this library.

https://www.activeandroid.com/

Tony Topper
  • 402
  • 6
  • 14
  • Nice framework, but it conflicts with org.codehous.jackson library, so if you use it in your project you wil be unable to use ActveAndroid – endryha Mar 14 '11 at 10:37
  • 1
    How does it conflict? Did you report it as a bug in http://tracker.activeandroid.com/? – Michael Pardo May 16 '11 at 14:14
  • Maybe have a look at http://androrm.the-pixelpla.net/ it has most of the features and i would say even some more. Plus: it is free and open source. – philgiese Jun 25 '11 at 12:30
6

I'm also looking for an ORM on Android. I tested ActiveAndroid, NeoDatis and db4o, and I think that I'll use one of the two last.

NeoDatis and db4o are really similar, so I would like some advice to choose the best one. Is someone using one of them on his project ? I'll use it for free and paid app, but it seems that the two haven't any license limitation for Android.

There is a benchmark here that seems to say that NeoDatis is faster than db4o, but I don't know if we can base my opinion on this.

JJD
  • 50,076
  • 60
  • 203
  • 339
Chayy
  • 834
  • 4
  • 12
  • 24
6

https://github.com/ahmetalpbalkan/orman

Orman framework might help you. It is especially designed for that and very small and useful.

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
3

One more newcomer: android-active-record. It's very lightweight and easy for use persistence framework for Android backed by SQLite http://code.google.com/p/android-active-record/

Vladimir Kroz
  • 5,237
  • 6
  • 39
  • 50
2

ActiveRecordJS from Aptana is a Javascript ORM that should run on the gPhone. It is designed to work with Jaxer and Gears. When you user the Jaxer Adapters, you can connect to SQLLite.

UPDATE: I don't think I made it clear, but ActiveRecordJS is an ORM that runs client side, which could be an advantage to you on the gPhone.

David Robbins
  • 9,996
  • 7
  • 51
  • 82
  • In Java code? Or in JavaScript code? – GWLlosa Feb 16 '09 at 01:10
  • I'm pretty sure what you're talking about is a Javascript solution intended purely for browser-based (Web) applications. I don't see how it relates to native app development for Android. – Brian Lacy May 09 '10 at 05:12
2

http://hadi.sourceforge.net

This tool is very simple and easy to use.

9tcat
  • 21
  • 1
1

My own DroidParts /http://droidparts.org/ just reached v0.5. It's a DI/ORM library & more.
Not much documentation, but includes a sample app.

yanchenko
  • 56,576
  • 33
  • 147
  • 165
1

I have developed my own implementation of the JPA ORM for Android. It is not yet fully feature complete, but you can annotate class with the @Entity, @Id, @Column annotations and you get JPA entities that can be stored and retrieved from the SQLite database. It needs some more features & cleanup before I'll post it to the public, but if there is enough interest it might accelerate my effort.

Pavel Lahoda
  • 219
  • 1
  • 4
  • 7
1

Even though this is an old post, the topic is still relevant. Hence, I want to share an interesting article and nice approach to solving most of the issues mentioned in the question:

http://blog.codecentric.de/en/2011/04/android-persistence-accelerated-small-inhouse-orm/

Hope anyone finds this as useful as myself!

Sgali
  • 362
  • 2
  • 12
0

Had negative experience with db4o (v. 8): indexing didn't work properly (exception etc.). So I didn't managed how to avoid creating duplicates in foreign tables when having object in object structure. More detailed explanation in my question. Hope one day it would be better.

Community
  • 1
  • 1
Oleksii Malovanyi
  • 6,780
  • 6
  • 24
  • 27