Design pattern for object-relational mapping
I have several related database tables and I would like to treat their rows as objects and their tables as something like lists. What are the considerations that I have to keep in mind (for instance, ensuring that the objects stay consistent with one another and with the database, lazy loading)? And what is a go开发者_JAVA百科od design pattern for implementing this? As I imaging the answer is pretty involved, a link to a good website would suffice.
On the other hand, if someone knows of Hibernate-like thing that really works on Android, I might give that a whirl (although it's a little heavy weight for me right now).
One of the best places to look for best practices on this subject is Chapter 31 - Object persistence and databases in Object-Oriented Software Construction by Bertrand Meyer.
You may have particular reasons for taking this approach, but it's not necessarily the right thing to do. See, for example http://c2.com/cgi/wiki?FirstGreatBlunder
I don't know much about Andriod, but for straight java development I prefer libraries such as EmpireDB http://incubator.apache.org/empire-db/ to O/R mapping frameworks. A database is, after all, a tool designed to do data manipulation.
精彩评论