这是我定义的表格字段:
@DatabaseField(uniqueCombo = true, columnName = COLUMN_NAME_FEED_PROVIDER_TYPE, canBeNull = false)
private int mFeedProviderType;
@DatabaseField(uniqueCombo = true, columnName = COLUMN_NAME_FEED_PROVIDER_SUB_TYPE)
private String mSubType;
@DatabaseField(columnName = COLUMN_NAME_DATE, canBeNull = false)
private long mDate;
我设法添加了1行。但是当我尝试添加第二行时这次更改mSubType字符串字段,它会抛出并且除外:
at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:135)
at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:450)
at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:310)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
at com.j256.ormlite.android.AndroidDatabaseConnection.insert(AndroidDatabaseConnection.java:169)
at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:91)
at com.j256.ormlite.android.AndroidDatabaseConnection.insert(AndroidDatabaseConnection.java:155)
答案 0 :(得分:0)
即使你使用uniqueCombo,你也需要一个id。所以添加一个这样的generatedId注释:
@DatabaseField(generatedId = true)
private int _id;//主键id