我有一个小问题,OrmLite在Android。

当我增加数据库的版本,onUpgrade方法如预期在我的OrmLite助手调用。升级后,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

我不知道为什么被清除的连接是不一样的救一个。

我也把我的数据库功能(插入...)到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);
    }
}

我认为这是一些简单的我失踪。

在此先感谢你的努力。

有帮助吗?

解决方案

好的,我看到的问题和它存在,不幸的是,在样本程序为好。在 ORMLite 辅助类中,onUpgrade方法应该使用:

onCreate(db, connectionSource);

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

onCreate(db);

我在已固定在HelloAndroid示例程序再现这个问题。我也适当的OrmLiteSqliteOpenHelper基类中ORMLite代码的Android的侧固定这一点。遗憾的问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top