We're using Robospice on Android in Scala with the ORMLite module for persistence and are having difficulties saving foreign collections to the database. The data is being received properly (i.e. we are getting and interpreting a User with a couple Posts properly) but when the time comes to save the data to cache it fails to save the foreign collection.
We've been getting this exception through the console but as you can see the User does have a setter and getter so we're not sure what the problem may be.
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)
Here is the User Model.
@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
}
}
And the Post model.
@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
}
}
Is there anything that we're doing wrong here? Or is this just a bug with Scala and ORMLite? Any help with this would be greatly appreciated.