I am reading data in gson from some web api. I want to insert rows in database in same order as they come in api result. Now when I am inserting data using ormlite with .callBatchTasks(new Callable<Void>() {}
method, it inserts data in wrong order. In fact, it automatically inserts data by primary key. This means the data is ordered by primary key. In my model class I have used that column as id = true
, nothing else.
This is the same when I do not use CallBatchTasks function of dao.
Edited -----
But this is problem I have faced , what I had to do was I removed id = true from column and ran the same code then data was inserted in correct order that I wanted. Means data was Like
id value
2 data1
3 data2
1 data3
35 data4
23 data5
Now when I had id = true for column in this model class then data was inserted as follows when I inspected in database:-
id value
1 data3
2 data1
3 data2
23 data5
35 data4
but when I removed id = true from model class , then data was inserted in correct order as :-
id value
2 data1
3 data2
1 data3
35 data4
23 data5
I do not know where I was getting it all wrong in ormlite.First I had thought that it is problem while retrieving then I inspected the database and I was inserting data in wrong order.