Create a list of object

196 views
Skip to first unread message

Stan Kocken

unread,
Feb 7, 2012, 11:52:27 AM2/7/12
to ORMLite Users
Hi,

I want to save a very long list of object (more than 2000 elements)
with ORMLite.
If I do :
for(ObjectToSave object : listObjectToSave) {
dao.create(object);
}
It's very long. I think it's due to ORMLite create one transaction for
each "create(Object object)", isn't it ?
There is a way to save the list with only one transaction ? Like
dao.create(listObjectToSave).

Sorry for my english,

Thanks

Stan

Gray Watson

unread,
Feb 7, 2012, 12:55:14 PM2/7/12
to ormlit...@googlegroups.com
On Feb 7, 2012, at 11:52 AM, Stan Kocken wrote:

> I want to save a very long list of object (more than 2000 elements) with ORMLite.

> It's very long. I think it's due to ORMLite create one transaction for each "create(Object object)", isn't it ?

No. ORMLite does not create a transaction at all unless you ask for them using the transaction manager. The problem most likely is that most databases are un "auto-commit" mode. That means that they synchronize to storage on every call. I would suggest you look into the batch operations dao method:

http://ormlite.com/docs/batch

Here's some more data:

http://ormlite.com/docs/transactions

If you put all of your inserts inside of the call() method than it will turn off auto-commit, start a transaction, and then commit the transaction when call() returns and restore the auto-commit setting.

gray

Stan Kocken

unread,
Feb 8, 2012, 8:09:28 AM2/8/12
to ormlit...@googlegroups.com
This is perfect !!! Thanks you so much !

2012/2/7 Gray Watson <256...@gmail.com>



--
Stan Kocken
Backelite - Ingénieur Développeur Android
7 Rue de Bucarest - 75008 Paris
stan....@backelite.com

Reply all
Reply to author
Forward
0 new messages