我们在Scala中使用Android上的Robospice和ORMLite模块进行持久化,并且在将外部集合保存到数据库时遇到了困难。数据正在正确接收(即我们正在使用几个帖子正确地解释和解释用户)但是当需要将数据保存到缓存时,它无法保存国外集合。
我们已通过控制台获得此异常,但您可以看到用户确实有一个setter和getter,因此我们不确定问题可能是什么。
java.lang.IllegalArgumentException: Could not find appropriate set method for private java.util.Collection scaloid.scala_test.models.User.posts
at com.j256.ormlite.field.DatabaseFieldConfig.findSetMethod(DatabaseFieldConfig.java:576)
at com.octo.android.robospice.persistence.ormlite.InDatabaseObjectPersister.saveAllForeignObjectsToCache(InDatabaseObjectPersister.java:192)
at com.octo.android.robospice.persistence.ormlite.InDatabaseObjectPersister$1.call(InDatabaseObjectPersister.java:96)
at com.octo.android.robospice.persistence.ormlite.InDatabaseObjectPersister$1.call(InDatabaseObjectPersister.java:91)
at com.j256.ormlite.misc.TransactionManager.callInTransaction(TransactionManager.java:168)
at com.j256.ormlite.stmt.StatementExecutor.callBatchTasks(StatementExecutor.java:553)
at com.j256.ormlite.dao.BaseDaoImpl.callBatchTasks(BaseDaoImpl.java:633)
at com.j256.ormlite.dao.RuntimeExceptionDao.callBatchTasks(RuntimeExceptionDao.java:534)
at com.octo.android.robospice.persistence.ormlite.InDatabaseObjectPersister.saveDataToCacheAndReturnData(InDatabaseObjectPersister.java:91)
at com.octo.android.robospice.persistence.CacheManager.saveDataToCacheAndReturnData(CacheManager.java:77)
at com.octo.android.robospice.request.DefaultRequestRunner.saveDataToCacheAndReturnData(DefaultRequestRunner.java:265)
at com.octo.android.robospice.request.DefaultRequestRunner.processRequest(DefaultRequestRunner.java:172)
at com.octo.android.robospice.request.DefaultRequestRunner$1.run(DefaultRequestRunner.java:216)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
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:841)
这是用户模型。
@JsonIgnoreProperties(ignoreUnknown = true)
@DatabaseTable(tableName = "u_old")
class User @JsonCreator()() {
@JsonProperty("name")
@DatabaseField
var name: String = ""
@JsonProperty("email")
@DatabaseField
var email: String = ""
@JsonProperty("id")
@DatabaseField(id = true)
var id : Int = 0
@JsonProperty("posts")
@ForeignCollectionField
private var posts: util.Collection[Post] = null
def getPosts: util.Collection[Post] = this.posts
def setPosts(posts : util.Collection[Post]) : Unit = {
this.posts = posts
}
}
和Post模型。
@JsonIgnoreProperties(ignoreUnknown = true)
@DatabaseTable(tableName = "p_old")
class Post @JsonCreator()() {
@JsonProperty("title")
@DatabaseField
var title : String = ""
@JsonProperty("body")
@DatabaseField
var body : String = ""
@JsonProperty("id")
@DatabaseField(id = true)
var id : Int = 0
@JsonProperty("user")
@DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true)
private var user : User = null
def getUser : User = this.user
def setUser(user : User) {
this.user = user
}
}
我们在这里做错了什么吗?或者这只是Scala和ORMLite的错误?对此的任何帮助将不胜感激。