Ormlite android relationship advice

Is There Room for One More? – Hacker Noon

ormlite android relationship advice

Trigent experts share tips, tricks, and advice on innovations Also, by defining the relationship in the model classes, we could avoid the. OrmLite Android Performance For some background, we'll set the wayback machine to At the time, our first commercial Android project. Recommendation Result For DaCapo and Android ORM Benchmark. 55 xii What is the relationship between the persistence framework's.

I did the first run of it, then kind of drifted off.

  • Some thoughts about the new Room library for Android By Google.
  • Your Answer

Since then, a group of people have been making incremental changes, but the code has stayed largely the same from an architectural perspective. Its designed to be relatively implementation agnostic, and uses reflection. Since that time, a few new tools have surfaced. Also, since the dawn of Java, people have been saying reflection is really slow.

Kevin's Blog – OrmLite Android Performance

So, I dug around a bit. There is a benchmark which shows OrmLite to be roughly 12x slower on data reads.

ormlite android relationship advice

Most people find it hard to argue against their beliefs, especially in a one sided conversation. GreenDAO is going to be faster in most cases, but often marginally so. Reads, as presented, are much slower.

If you want a sensational sound byte, being similarly unfair, GreenDAO is 4. Its only slower if you cripple the benchmark.

Tutorial Android - Cap. 10 - SQLite con ORMLite

See how that works? OrmLite is still slower, though, right? Yeah, but OrmLite is annotating your actual object models.

ormlite android relationship advice

One of the value props of an ORM is that it maps to your object model, not an object model. Its still your object model.

Where to find me

You also need to be careful with joins and foreign collections. What is easier to code to? This would be the correct code model for my customer addresses: The code knows there can be multiple and perhaps iterate over them during checkout so I can select where I want my items to ship.

But when charging my credit card, it uses the one and only billing address. If I want to say "a Customer can have one billing address but many shipping addresses," then a Customer would contain a single billing address reference, but a collection of shipping address references.

The cardinality in the relationship is encapsulated in the cardinality of the references: There is a one-to-one relationship between Customer and billing address, and a one-to-many relationship between Customer and shipping address. In the question you indicate you don't quite understand why the cardinality must be specified but in more wordsyet here you say you understand why. If you take an object model without any specified cardinalities for a relation between two classes A and B, an ORM could always treat it like a potential many-to-many relationship.

Since any many-to-many relationship on the DB could also be used to store just one-to-one or one-to-many relations, technically this would work. However, this approach would have two big disadvantages: It would be extremely wasteful.

ormlite android relationship advice

Note the additional link table would be not required if the ORM would know beforehand that a relation is just 1: For example, having always to deal with superfluous records in the link table, as well as with SQL statements which are twice as complex as they need to be is a big waste of storage and CPU time. Same holds for your generated client code - getting a collection in a class just for storing one single value does make the code using this collection more complicated, it needs more memory and is potentially slower.

The database and the generated code cannot ensure data integrity for you, so if from a business point of view a relationship must not be many-to-many, but 1: For example, when there is a collection used for a 1: If, however, your class would only contain a reference to a single object instead of a collection, it cannot be used in a wrong manner, so there is no additional code needed.