I have the following entities and relationship in order to save the configuration defined by the user. The relationship looks like one to many nested relationship.
@Entity(tableName = "gatt_configuration")
data class GattConfiguration(
@PrimaryKey(autoGenerate = true)
val id: Long,
val name: String
)
@Entity(tableName = "config_service")
data class ConfigService(
@PrimaryKey
val uuid: String,
val name: String,
val type: Int,
val configurationId: Long // Foreign key to GattConfiguration
)
@Entity(tableName = "config_characteristic")
data class ConfigCharacteristic(
@PrimaryKey
val uuid: String,
val name: String,
val properties: Int,
val permissions: Int,
val serviceUuid: String // Foreign key to ConfigService
)
@Entity(tableName = "config_descriptor")
data class ConfigDescriptor(
@PrimaryKey
val uuid: String,
val name: String,
val characteristicUuid: String // Foreign key to ConfigCharacteristic
)
data class GattConfigurationWithServices(
@Embedded val configuration: GattConfiguration,
@Relation(
parentColumn = "id",
entityColumn = "configurationId"
)
val services: List<ConfigServiceWithCharacteristics>
)
data class ConfigServiceWithCharacteristics(
@Embedded val service: ConfigService,
@Relation(
parentColumn = "uuid",
entityColumn = "serviceUuid"
)
val characteristics: List<ConfigCharacteristicWithDescriptors>
)
data class ConfigCharacteristicWithDescriptors(
@Embedded val characteristic: ConfigCharacteristic,
@Relation(
parentColumn = "uuid",
entityColumn = "characteristicUuid"
)
val descriptors: List<ConfigDescriptor>
)
And here is my room query so that each gatt configuration should have all the nested records i-e gatt configuration should have its own list of services, each service has its own list of characteristics and each characteristics has its own list of descriptors.
@Transaction
@Query(“SELECT * FROM gatt_configuration”)
fun getAllGattConfigurationsWithServices(): Flow<List>
Code to define Database
@Database(
entities = [
GattServer::class,
GattConfiguration::class,
ConfigService::class,
ConfigCharacteristic::class,
ConfigDescriptor::class
],
version = 1,
exportSchema = false
)
@TypeConverters(TypesConverter::class)
abstract class GattServersDatabase: RoomDatabase() {
abstract fun gattServersDao(): GattServerDao
}
Compile time error is
ConfigServiceWithCharacteristics.jave.4 error: The class must be
either @Entity or @DatabaseView.
Please assist me in resolving this issue. Thanks in advance.