Reputation: 143
I'm trying to upgrade a ormlite/sqlite android db.
I have a java class like this:
@DatabaseTable
public class Assessment {
@DatabaseField(generatedId = true)
private Long assessmentId;
@DatabaseField
private java.lang.String assessmentName;
...
}
and want it to change like this:
@DatabaseTable
public class Assessment {
//Change from autoincrement to insertable id
@DatabaseField(id = true)
private Long assessmentId;
@DatabaseField
private java.lang.String assessmentName;
//NEW FIELD
@ForeignCollectionField
private java.util.Collection<AssessmentEntry> assessmentEntries;
...
}
And i created a new model class:
@DatabaseTable
public class AssessmentEntry implements Comparable<AssessmentEntry>{
@DatabaseField(id = true)
private Long AssessmentEntryId;
@DatabaseField
private String entryName;
@DatabaseField
private int orderNumber;
@DatabaseField(foreign = true)
private Assessment assessment;
...
}
I also use the OrmLiteConfigUtil to create a mapping file (if this is relevant).
Now I'm trying to add these changes to the database via onUpgrade(...)
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int oldVersion, int newVersion) {
if(oldVersion < 2) {
try {
//Create new table
TableUtils.createTable(connectionSource, AssessmentEntry.class);
//implement changes for class Assessment
} catch (SQLException e) {
e.printStackTrace();
}
}
}
So my question is: do I need to change the assessment table via raw query to apply the change from generatedId to id? And do i need to make any ormlite specific changes because of the foreign collection in table assessment?
Upvotes: 0
Views: 102
Reputation: 116908
So my question is: do I need to change the assessment table via raw query to apply the change from generatedId to id?
Yes you do. I'd compare sqlite output to see what it expects there. You may need to create a new assessmentId2
column, assign it the value of the current assessmentId
, then delete the current one and rename the new one back to assessmentId
.
Do i need to make any ormlite specific changes because of the foreign collection in table assessment?
No. All the foreign-collection wants is an id. How it gets created is immaterial.
Upvotes: 1