I've an entity called Events which is defined as follows:
@Entity(tableName = "Events")
data class Event(@PrimaryKey val id: Long, val name: String, val venues: Set<String>, val rating: Int)
I've a pair of @TypeConverter
methods for handling Set<String>
:
@TypeConverter
fun fromStringToStringSet(str: String): Set<String> = str.split("<|>")
@TypeConverter
fun fromStringSetToString(set: Set<String>): String = set.joinToString("<|>")
In my Dao
, I've a method annotated with @Query
as follows:
@Query("UPDATE Events SET name = :name, venues = :venues WHERE id = :id")
fun updateAndRetainRating(id: Long, name: String, venues: Set<String>)
When I try to update an event with 2 venues, I get a runtime error telling me that the SQL couldn't be compiled. The generated SQL is:
UPDATE Events SET name = ?, venues = ?,? WHERE id = ?
This is obviously wrong. Looking into the generated code, Room is getting the size of Set<String>
and adding the same number of ?
s.
Why isn't my TypeConverter
being used? I don't face this issue in other queries(@Insert
and @Query
(for SELECT
)). Other TypeConverter
s are also working fine.
EDIT: The same issue also occurs if I use List<String>
+ TypeConverter
s instead of Set<String>
.