0

This question already has an answer here:

I am developing an Android app in which I have to add chat functionality. Also, I have to save the chat history. I will accomplish this task using SQlite. But, I am not sure whether should I consider using an ORM like GreenDAO or ORMLite or I should use traditional way of persisting data in SQLite.

Actually, I am not clear when should go for using an ORM and how do I get benefit from it.

marked as duplicate by Doc Brown, gnat, user7007, gbjbaanb, user40980 Jan 6 '14 at 16:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @DocBrown Hi, could you please explain how is it irrelevant. Do you mean to say an orm is not beneficial for a mobile platform or I misunderstood something – Nitish Jan 6 '14 at 12:15
  • 1
    Quite the opposite. The reasons for using or not using an ORM are the same if you are on a mobile platform, a desktop platform, a web platform etc. So mentioning "Android" in the title or tags is IMHO irrelevant for the question and the potential answers. That's why I consider the question as a duplicate of the one I have linked to: the other question mentions "PHP", which is the only main difference between those two questions, but of no importance for answering it. – Doc Brown Jan 6 '14 at 12:33
  • @DocBrown Thanx. Now, I understood... – Nitish Jan 6 '14 at 12:36
4

There are two fundamental reasons for using ORM tools. Knowing which one applies to you makes the decision easier.

Many people use automatic mapping because they don't want to deal with database access at all. Maybe they don't understand it, or they don't want to think about it, or they are certain that they will never require any functionality that goes beyond the lowest common denominator of relational persistence that ORM can give you. In that case, this is a useful trade-off: less development work on peripheral issues equals more time to spend on developing core issues. The price, of course, is loss of control and expressiveness for advanced persistence strategies - usually, you'd hope, precisely the advanced stuff you weren't going to use anyway.

Others want a strong abstraction from the actual data storage because they anticipate that they might change their database, or have to support different engines from the get-go. In that case, the tools help you by ensuring that you don't intermix low-level and business-level logic at all. In other words, all the things that would cause additional work if you later changed databases are automatically prohibited. This is a useful method of enforcing development discipline for things you shouldn't do anyway (but might do by accident). However, the benefits are real only if you actually rip out and replace your persistence provider - otherwise, they contribute to the normal good practice of layering/not repeating yourself etc., but not more than that. If you're on a mobile platform and have no choice in which database will power your app, then this motivation doesn't really make sense.

  • 1
    +1, I think one should highlight a reason that you may had in mind (at least partially) in your "reason 1": people don't want to write tedious CRUD code again and again. – Doc Brown Jan 6 '14 at 12:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.