Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获得;“唯一约束失败”;使用Ormlite createOrUpdate()方法时发生异常_Java_Android_Ormlite - Fatal编程技术网

Java 获得;“唯一约束失败”;使用Ormlite createOrUpdate()方法时发生异常

Java 获得;“唯一约束失败”;使用Ormlite createOrUpdate()方法时发生异常,java,android,ormlite,Java,Android,Ormlite,我在整个应用程序中有几个调用,其中数据库中的表通过调用.createOrUpdate() 来自此的调用: 这是一种方便的方法,用于在数据库中创建项目(如果没有) 存在。id从数据参数中提取,并按id进行查询 是在数据库上创建的。如果数据库中的行具有相同的id 存在,则数据库中的所有列都将从更新 数据参数中的字段。如果id为null(或0或其他值) 其他默认值)或不存在于数据库中,则该对象 将在数据库中创建。这也意味着您的数据项 必须定义id字段 我的理解是,在调用createOrUpdate()

我在整个应用程序中有几个调用,其中数据库中的表通过调用
.createOrUpdate()

来自此的调用:

这是一种方便的方法,用于在数据库中创建项目(如果没有) 存在。id从数据参数中提取,并按id进行查询 是在数据库上创建的。如果数据库中的行具有相同的id 存在,则数据库中的所有列都将从更新 数据参数中的字段。如果id为null(或0或其他值) 其他默认值)或不存在于数据库中,则该对象 将在数据库中创建。这也意味着您的数据项 必须定义id字段

我的理解是,在调用createOrUpdate()时,如果数据库不包含行,则底层代码应该调用“insert”,如果行存在,则应该调用“update”

似乎发生的是,当导致异常的行已经存在时,底层代码正在调用“insert”

有人知道为什么会发生这种情况或者如何避免吗

以下例外情况:

java.lang.RuntimeException: java.sql.SQLException: Unable to run insert stmt on object
    Feed(id=126275579_organisations-email_58284484, type=organisations-email, category=1, msg=<p>Body</p>, regarding=Bobby Castle, subject=Subject, createdTs=2016-01-04T09:59:27+00:00, completed=0, read=0, starred=0, archived=0, remoteAttachments=[], localAttachments=null, authorId=250008275, authorName=Live Regression Test, authorImg=null): INSERT INTO `feed` (`id` ,`type` ,`category` ,`msg` ,`regarding` ,`subject` ,`createdTs` ,`completed` ,`read` ,`starred` ,`archived` ,`authorId` ,`authorName` ,`authorImg` ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
     at com.j256.ormlite.dao.RuntimeExceptionDao.createOrUpdate(RuntimeExceptionDao.java:252)
     at uk.co.test.test.data.orm.models.Feed.createOrUpdate(Feed.java:81)
     at uk.co.test.test.interactors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:308)
     at uk.co.test.test.interactors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:290)
     at uk.co.test.test.interactors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:27)
     at uk.co.test.test.interactors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:12)
     at uk.co.test.test.interactors.common.CallbackRunnable.success(CallbackRunnable.java:127)
     at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
     at java.lang.Thread.run(Thread.java:818)
Caused by: java.sql.SQLException: Unable to run insert stmt on object Feed(id=126275579_organisations-email_58284484, type=organisations-email, category=1, msg=<p>Body</p>, regarding=Bobby Castle, subject=Subject, createdTs=2016-01-04T09:59:27+00:00, completed=0, read=0, starred=0, archived=0, remoteAttachments=[], localAttachments=null, authorId=250008275, authorName=Live Regression Test, authorImg=null): INSERT INTO `feed` (`id` ,`type` ,`category` ,`msg` ,`regarding` ,`subject` ,`createdTs` ,`completed` ,`read` ,`starred` ,`archived` ,`authorId` ,`authorName` ,`authorImg` ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
     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 com.j256.ormlite.dao.BaseDaoImpl.createOrUpdate(BaseDaoImpl.java:336)
     at com.j256.ormlite.dao.RuntimeExceptionDao.createOrUpdate(RuntimeExceptionDao.java:249)
     at uk.co.test.test.data.orm.models.Feed.createOrUpdate(Feed.java:81) 
     at uk.co.test.test.interactors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:308) 
     at uk.co.test.test.interactors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:290) 
     at uk.co.test.test.interactors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:27) 
     at uk.co.test.test.interactors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:12) 
     at uk.co.test.test.interactors.common.CallbackRunnable.success(CallbackRunnable.java:127) 
     at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:818) 
Caused by: java.sql.SQLException: inserting to database failed: INSERT INTO `feed` (`id` ,`type` ,`category` ,`msg` ,`regarding` ,`subject` ,`createdTs` ,`completed` ,`read` ,`starred` ,`archived` ,`authorId` ,`authorName` ,`authorImg` ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
     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.stmt.StatementExecutor.create(StatementExecutor.java:450) 
     at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:310) 
     at com.j256.ormlite.dao.BaseDaoImpl.createOrUpdate(BaseDaoImpl.java:336) 
     at com.j256.ormlite.dao.RuntimeExceptionDao.createOrUpdate(RuntimeExceptionDao.java:249) 
     at uk.co.test.test.data.orm.models.Feed.createOrUpdate(Feed.java:81) 
     at uk.co.test.test.interactors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:308) 
     at uk.co.test.test.interactors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:290) 
     at uk.co.test.test.interactors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:27) 
     at uk.co.test.test.interactors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:12) 
     at uk.co.test.test.interactors.common.CallbackRunnable.success(CallbackRunnable.java:127) 
     at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:818) 
Caused by: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: feed.id (code 1555)
     at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
     at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782)
     at android.
java.lang.RuntimeException:java.sql.SQLException:无法在对象上运行insert stmt
Feed(id=126275579_organizations-email_58284484,type=organizations-email,category=1,msg=Body

,about=Bobby Castle,subject=subject,createdTs=2016-01-04T09:59:27+00:00,completed=0,read=0,starred=0,archived=0,remoteAttachments=0,localAttachments=null,authorId=250008275,authorName=Live回归测试,authorMg=null):在“提要”(`id`、`type`、`category`、`msg`、`About`、`subject`、`createdTs`、`completed`、`read`、`starred`、`archived`、`authorName`、`authorName`、`authorName`)中插入值(?、、、、、、、、、、、、、、、、、、、、?) 在com.j256.ormlite.dao.RuntimeExceptionDao.createOrUpdate(RuntimeExceptionDao.java:252) 在uk.co.test.test.data.orm.models.Feed.createOrUpdate(Feed.java:81)上 在uk.co.test.test.interactiors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:308) 在uk.co.test.test.interactiors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:290)上 在uk.co.test.test.interactiors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:27)上 在uk.co.test.test.interactiors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:12)上 在uk.co.test.test.interactiors.common.CallbackRunnable.success(CallbackRunnable.java:127)上 CallbackRunnable$1.run(CallbackRunnable.java:45) 位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 运行(Thread.java:818) 原因:java.sql.SQLException:无法在对象提要上运行insert stmt(id=126275579_organizations-email_58284484,type=organizations-email,category=1,msg=Body

,about=Bobby Castle,subject=subject,createdTs=2016-01-04T09:59:27+00:00,completed=0,read=0,stared=0,archived=0,remoteAttachments=[],localAttachments=null,authorId=250008275,authorName=Live回归测试,authorMg=null):插入“提要”('id`、'type`、'category`、'msg`、'about`、'subject`、'createdTs`、'completed`、'read`、'starred`、'archived`、'authorName`、'authorMg`)值(?,,,,,,,,,,,,,,,,,,,,,,,,,,,?) 位于com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22) 在com.j256.ormlite.stmt.MappedCreate.insert(MappedCreate.java:135)上 位于com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:450) 位于com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:310) 位于com.j256.ormlite.dao.BaseDaoImpl.createOrUpdate(BaseDaoImpl.java:336) 在com.j256.ormlite.dao.RuntimeExceptionDao.createOrUpdate(RuntimeExceptionDao.java:249) 在uk.co.test.test.data.orm.models.Feed.createOrUpdate(Feed.java:81)上 在uk.co.test.test.interactiors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:308) 在uk.co.test.test.interactiors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java:290)上 在uk.co.test.test.interactiors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:27)上 在uk.co.test.test.interactiors.common.StandardCallbackRunnable.checkStandardResponse(StandardCallbackRunnable.java:12)上 在uk.co.test.test.interactiors.common.CallbackRunnable.success(CallbackRunnable.java:127)上 CallbackRunnable$1.run(CallbackRunnable.java:45) 位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 运行(Thread.java:818) 导致:java.sql.SQLException:插入到数据库失败:插入到“提要”(`id`、`type`、`category`、`msg`、`about`、`subject`、`createdTs`、`completed`、`read`、`starred`、`archived`、`authorName`、`authorMg`)值(?、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 位于com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22) 位于com.j256.ormlite.android.AndroidDatabaseConnection.insert(AndroidDatabaseConnection.java:169) 位于com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:91) 位于com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:450) 位于com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:310) 位于com.j256.ormlite.dao.BaseDaoImpl.createOrUpdate(BaseDaoImpl.java:336) 在com.j256.ormlite.dao.RuntimeExceptionDao.createOrUpdate(RuntimeExceptionDao.java:249) 在uk.co.test.test.data.orm.models.Feed.createOrUpdate(Feed.java:81)上 在uk.co.test.test.interactiors.server.CategoryInteractor$6.onSuccessfulResponse(CategoryInteractor.java
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
synchronized (dao) {
    status = dao.createOrUpdate(...);
}