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.


当前回答

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

其他回答

我已经为Android开发了我自己的JPA ORM实现。它还没有完全完成功能,但是您可以使用@Entity、@Id、@Column注释注释类,并且您可以获得可以从SQLite数据库存储和检索的JPA实体。在我将它发布到公众之前,它需要更多的功能和清理,但如果有足够的兴趣,它可能会加速我的努力。

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

我不知道你到底想要什么,但是如果你的体系结构需求是灵活的,有一个替代SQLite的选择,你可能会发现它很有用。db4o可能值得一试:

Android db4o 代码比较示例

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

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

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。