Closed nskola closed 2 years ago
Hi @nskola could you share the project to validate the issue? or maybe share the code related with the db, dao, entities, database? to see what it's happening.
Also only to let you know, the demo
folder in the repository is an example app saving custom entities.
I actually started converting the database related classes to Kotlin now. I'll let you know if that solves the issue.
Hi @dalgarins , Kotlin convert had no effect, contract entity is still not created in database. Here is the database related code:
Dagger module where db is initialized:
@Module
class RoomModule(mApplication: Application) {
private val appDataBase: AppDatabase =
SpatiaRoom.databaseBuilder(mApplication, AppDatabase::class.java, "database")
.fallbackToDestructiveMigration()
.build()
}
AppDataBase.kt
@Database(entities = [Contract::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun contractDao(): ContractDao
}
ContractDao.kt
@Dao
abstract class ContractDao : BaseDao<Contract>() {
@Query("SELECT * FROM contract")
abstract fun allContracts(): Single<List<Contract>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract override fun insert(dbitem: Contract)
@Delete
abstract fun delete(contract: Contract?)
@Query("SELECT * FROM contract WHERE id = :id")
abstract override fun getById(id: Long): Contract?
}
Contract.kt
@Entity
class Contract(
val name: String,
override val id: Long,
val machine_id: Long
) : IDataBaseModel {
@PrimaryKey(autoGenerate = true)
override var localId: Long = 0
override var isWaitingSync = false
}
@nskola I decided to modify the demo app and add dagger and hilt in my case with the library and everything is working,
the variable contract has all the contracts saved in the db.
the repo branch is: room-hilt
maybe you want to review.
I think your issue it's related with database version in the AppDatabase
if you had the app installed and only you updated the class without upgrade version that could be the issue.
I'm going to close the issue because the library it's working and seems to be another problem related with your project.
@nskola let me know if was useful or if you were able to solve the issue?
I didn't find the cause. It may have something to do with the room library version numbers or something. The problem wasn't in the database versioning, because I reinstalled the app between launches. Thank you anyway.
@nskola Which room version are you using?
have you test the branch that I created for you?
could you create an app only with the code of database and all interfaces that you have created in your code, and share with me the zip? I will review that.
Room version 2.3.0.
I ended up with different solution, but I will test the branch later.
@nskola there were a break change with android room: 2.3.0, right now the issue is fixed, I have updated the README. Please read it to get more information.
I'm trying to use this library with existing Android project. It's written in Java, so the models, daos and appDataBase class are also Java classes. I managed to initialize the spatia-room database but my own database models/tables are not found in the database. Only the geospatial related default tables are created. Do you know if the problem is related to java/kotlin interaction or something else? I don't get any build time errors.