0

I get an array with a not specified number of BlueCones with different x and y Values, every 0.5s I receive new BlueCones that should Replace the old Cones in the "blue_cone" table how can I auto-generate Keys that always start with 0 for new Incoming Cones.

@Entity(tableName ="blue_cones")
data class BlueCone(

val x: Double = 0.0,
val y: Double = 0.0

){
@PrimaryKey(autoGenerate = true)
var blueId: Int = 0

}
Strohhut
  • 490
  • 1
  • 6
  • 22

1 Answers1

0

Room does not support resetting the primary keys, which are UNIQUE. one option would be adding two further fields, which form a combined key: eg. sequence (the number of the request) & coneId, where coneId could start over at 0, with every new request/response. I've also once explained here how to reset an auto-incremental value, in case it has to be (but ordinary this is not recommend).

as @Advice-Dog suggested yesterday, blue & yellow should be properties of class Cone. can only confirm, that this would make sense, with high probability... unless there is a strict requirement, to store them in two separate tables.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216