2010-11-24 3 views
4

Android의 OrmLite에 약간의 문제가 있습니다.Android 및 OrmLite : OnUpgrade 실패

데이터베이스 버전을 증가시킬 때 onUpgrade 메서드가 OrmLite 도우미에서 예상대로 호출됩니다. 업그레이드 후, onCreate 방법이라고 나는이 예외 얻을 수있다 :

11-24 10:09:45.720: ERROR/AndroidConnectionSource(390): connection saved 
    [email protected] is not the one 
    being cleared [email protected] 

지워진 연결이 저장된 것과 동일하지 왜 단서가 없다합니다.

또한 데이터베이스 기능 (삽입 ...)을 OrmLite Helper 클래스에 넣었습니다. 어쩌면 이것이 문제가 될 수 있겠습니까?!?

A는 내 헬퍼 클래스에서 니펫을 :

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); 
    } 
} 

나는 내가 부족 간단하게 뭔가 생각합니다.

미리 감사드립니다.

+0

언급하는 것을 잊었습니다 : OrmLite 버전 4.5 – saxos

+0

전체 예외 스택 saxos를 게시 할 수 있습니까? 감사. – Gray

답변

7

그래, 문제가 발생하고 불행히도 샘플 프로그램에서도 문제가 발생합니다. ORMLite 헬퍼 클래스에서 onUpgrade 방법을 사용해야합니다

onCreate(db, connectionSource); 

을 대신 서브 클래스 호출하는 다음의 : 내가 된 HelloAndroid 예제 프로그램에서이 문제를 재현 한

onCreate(db); 

을 결정된. ORMLite 코드의 안드로이드 측 기본 클래스 인 OrmLiteSqliteOpenHelper에서도이를 올바르게 수정했습니다. 죄송합니다.

+0

쿨, 내 문제가 해결되었습니다. 빠른 응답과 노력에 감사드립니다. 정말 고맙게 생각하고 계속 노력하겠습니다. – saxos