Android和OrmLite:OnUpgrade失败

sax*_*xos 4 android ormlite

我在Android上的OrmLite有一个小问题.

当我增加数据库版本时,onUpgrade在我的OrmLite Helper中按预期调用该方法.升级后,onCreate调用该方法,我得到以下异常:

11-24 10:09:45.720: ERROR/AndroidConnectionSource(390): connection saved
    com.j256.ormlite.android.AndroidDatabaseConnection@44f0f478 is not the one
    being cleared com.j256.ormlite.android.AndroidDatabaseConnection@44f5d310
Run Code Online (Sandbox Code Playgroud)

我不清楚为什么清除的连接与保存的连接不一样.

我还将我的数据库函数(插入...)放入OrmLite Helper类中.也许这可能是个问题?!?

来自我的助手类的片段:

public class OrmLiteDBProvider extends OrmLiteSqliteOpenHelper
    implements IEntityProvider, IDBProvider {

//snip
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
    try {
        Log.i(OrmLiteDBProvider.class.getName(), "Creating database and tables");
        TableUtils.createTable(connectionSource, OrgManaged.class);
    } catch (SQLException e) {
        Log.e(OrmLiteDBProvider.class.getName(),
            "Can't create database and tables", e);
        throw new RuntimeException(e);
    }
}
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource,
   int oldVersion, int newVersion) {
    try {
        Log.i(OrmLiteDBProvider.class.getName(),
            "Database version changed. Dropping database.");
        TableUtils.dropTable(connectionSource, OrgManaged.class, true);
        // after we drop the old databases, we create the new ones
        onCreate(db);
    } catch (SQLException e) {
        Log.e(OrmLiteDBProvider.class.getName(), "Can't drop databases", e);
        throw new RuntimeException(e);
    }
}
Run Code Online (Sandbox Code Playgroud)

我觉得这很简单,我很想念.

在此先感谢您的努力.

Gra*_*ray 7

好的,我看到了问题,不幸的是,它也存在于示例程序中.在ORMLite帮助器类中,该onUpgrade方法应使用:

onCreate(db, connectionSource);
Run Code Online (Sandbox Code Playgroud)

而不是调用子类的以下内容:

onCreate(db);
Run Code Online (Sandbox Code Playgroud)

我已经HelloAndroid修复了示例程序中的这个问题.我还在OrmLiteSqliteOpenHelperORMLite代码的Android端的基类中正确修复了这个问题.抱歉,这个问题.