Saving a foreign collection in ORMLite with Robospice and Scala

We use Robospice on Android in Scala with the ORMLite module for persistence and have difficulty storing foreign collections in the database. The data arrives properly (for example, we receive and interpret the user with the message password properly), but when it comes time to save the data for caching, it is not possible to save someone else's collection.

We got this exception through the console, but as you can see, the user has a setter and a recipient, so we are not sure what could be the problem.

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 something we are doing wrong? Or is it just a mistake with Scala and ORMLite? Any help with this would be greatly appreciated.

+6
source share

Source: https://habr.com/ru/post/971942/


All Articles