A
A
Artem2016-05-19 21:57:10
Android
Artem, 2016-05-19 21:57:10

Should I use ORM with a large database?

I am writing an application, the application will have a database with a large table (more than 100,000 records). Each entry in the database is essentially a data model.
Initially, I planned to use ORMlite, but there are reviews that this approach will be inefficient with large amounts of data. Is it so? If yes, what is better to use in this case?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
lazard105, 2016-05-20
@bartwell

The problem with ORMlite is precisely in the mapping of objects. Due to reflection, it works very slowly, especially if a large amount of data is requested.
But this problem is easily solved by writing your own mapper for a specific table/query.
It's done like this:

// return the orders with the sum of their amounts per account
GenericRawResults<Foo> rawResults =
  orderDao.queryRaw(
    "select account_id,sum(amount) from orders group by account_id",
    new RawRowMapper<Foo>() {
            public Foo mapRow(String[] columnNames,
              String[] resultColumns) {
                return new Foo(Long.parseLong(resultColumns[0]),
                    Integer.parseInt(resultColumns[1]));
        }
    });

However, large queries are often difficult to form and optimize in object form, so such queries are easier to do directly (sql query via SQLiteOpenHelper). In this case, it is better to work with the cursor , and not with objects, in order to get rid of the mapping delay and memory costs.
(This applies only to really heavy requests)
PS Giant databases are usually in offline applications. If the presence of the Internet is necessary for the application to work, then it is better to transfer the data to the server.

A
Alexander Varakosov, 2016-05-20
@thelongrunsmoke

Usually, a giant database on a device is a sign of architectural problems. Clean up part of the data on the server, it is unlikely that they are needed in full in each session of working with the application.
ORM for this purpose also serves to facilitate work with big bases. I like GreenORM, some of the complexity of setting it up pays off in speed.

I
Ilya Pavlovsky, 2016-05-20
@TranE91

Choosing the type of ORM for mobile development will only give speed gains in object mapping. I used ORMLite for a long time, but decided to give up due to the difficulty of deploying large models and moronic DAOs. If there is a condition to use SQLite, look towards DBFlow. In general, the trend of the Object-Oriented Realm type database is now popular.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question