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.


当前回答

ActiveAndroid(20美元)看起来可能正是你所需要的。

其他回答

还有一个新来者:android-active-record。 它是一个非常轻量级且易于使用的持久性框架,支持SQLite http://code.google.com/p/android-active-record/

如果性能和代码大小很重要,请查看greenDAO。我是它的作者,我创建另一个ORM的动机是避免在热点中反射。结果表明,greenDAO的速度比ORMLite快4倍。有关详细信息,请查看功能页面。

这个问题不会变老,但建议的框架会变老。因此,这里首先列出了我在这类框架中发现的重要内容,以便进行比较:

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)

这里是一个框架的列表,并对以上几点进行了说明。我查找了一些像aBatis和Hadi这样的,但我只添加了2011年之后有一些活动的人。

http://ormlite.com, Maven artifact, 52 kB, SVN, the website is... difficult but there seem to be a lot of examples, according to http://ormlite.com/changelog.txt the last version is 4.48 from 2013, https://github.com/j256/ormlite-core (release tags), last activity March 2015 http://greendao-orm.com, good maintenance, Maven artifact, focus: fast performance, small size, little RAM consumption. Github: https://github.com/greenrobot/greenDAO/ (release tags, > 2300 stars), last activity November 2014 https://github.com/roscopeco/ormdroid, small size, last activity August 2014 http://www.activeandroid.com, https://github.com/pardom/ActiveAndroid (> 2300 stars), good maintenance, community, no release tags (download points to master tarball), Maven artifact, last activity October 2014 http://droidparts.org, https://github.com/yanchenko/droidparts (release tags, > 600 stars), also dependency injection, Maven artifact, actively maintained http://www.androrm.com , https://github.com/androrm/androrm (release tags), last activity Jan 02, 2014 (github) https://github.com/emilsjolander/sprinkles (release tags, > 600 stars), last activity May 2014, Maven artifact (thanks @AndroidGecko) http://realm.io, https://github.com/realm/realm-java replaces not only ORM but also SQLite, also for iOS (release tags, > 1600 stars), actively maintained, own Maven repository

我没有尝试过其中的任何一个,但也许我可以通过列出目前活跃的项目来节省当前读者的时间。如果你知道其他项目满足以上的一些要求,并且已经有了一些重要的开发(经过一段时间),请添加评论。

EDIT(2013年11月):更新列表到项目的当前状态。其中一些已经添加了发布标签到他们的github回购以及Maven/Gradle支持。干得好!

EDIT(2015年4月):更新列表,添加了Sprinkles(根据@AndroidGecko的评论)和Realm.io。

虽然这是一篇旧文章,但这个话题仍然是相关的。因此,我想分享一篇有趣的文章和解决问题中提到的大部分问题的好方法:

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

希望任何人发现这和我一样有用!

https://github.com/ahmetalpbalkan/orman

Orman框架可能会帮助您。它是专门为此设计的,非常小巧实用。