karnage karnage - 6 days ago 6
Android Question

Android & Ormlite: Inserting data in DatabaseHelper onCreate

I am using Ormlite for the first time and I am trying to setup my DatabaseHelper to insert rows after creating the database's tables. I am getting a

getWritableDatabase called recursively
error when I do.

Here is my onCreate:

public void onCreate(SQLiteDatabase sqliteDatabase, ConnectionSource connectionSource) {

try {
TableUtils.createTable(databaseType, connectionSource, User.class);

// Add test user
User test = new User("test", "12345");
getUserDao().create(test);


} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Unable to create databases", e);
}
}

Answer

The problem here was that @karnage was using an older version of ORMLite that had a bug with using the DAOs in the onCreate -- the pattern that he is using. This was fixed in version 4.6 (10/2010) and downloading and running the latest version works for him.

Here is the bug report:

https://sourceforge.net/tracker/?func=detail&aid=3117883&group_id=297653&atid=1255989

Here's the change log file to track new features and versions of ORMLite:

http://ormlite.com/changelog.txt

Comments