2014-09-30 62 views
2

創建獨特的組合行這是我定義的表中的字段:ORMLite不能在Android的

@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

即使你使用uniqueCombo,你需要一個id也。所以添加註釋generatedId像這樣:

@DatabaseField(generatedId = true) 
private int _id;//主鍵id 
+1

歡迎來到SO。請閱讀此[如何回答](http://stackoverflow.com/help/how-to-answer)以提供高質量的答案。 – thewaywewere 2017-05-31 01:29:20