title: How to insert, update and delete a many-to-many relationship in android room?
body: <p>Following the Android documentation for many-to-many relations, found here: <a href="https://developer.android.com/training/data-storage/room/relationships#many-to-many" rel="nofollow noreferrer">Define many-to-many relationships</a></p>
  <p>I have the following entities</p>
  <pre><code>@Entity
  class Song(
      @PrimaryKey val songId: Long,
      @ColumnInfo val name: String,
      @ColumnInfo val path: Uri,
  )
  </code></pre>
  <pre><code>@Entity
  data class PlaylistInfo(
      @ColumnInfo var name: String,
      @PrimaryKey(autoGenerate = true) val playlistId: Long = 0,
  )
  
  </code></pre>
  <p>Then I have an entity that is a cross-reference between the two.</p>
  <pre><code>@Entity(primaryKeys = [&quot;playlistId&quot;, &quot;songId&quot;])
  data class PlaylistSongCrossRef(
      val playlistId: Long,
      val songId: Long
  )
  </code></pre>
  <p>Lastly, I have a class that combines the two using the <code>PlaylistSongCrossRef</code> as a Junction.</p>
  <pre><code>data class Playlist(
      @Embedded val info: PlaylistInfo,
      @Relation(
          parentColumn = &quot;playlistId&quot;,
          entityColumn = &quot;songId&quot;,
          associateBy = Junction(PlaylistSongCrossRef::class)
      )
      val songs: MutableList&lt;Song&gt;
  )
  </code></pre>
  <p>I have then defined read queries in the Dao.</p>
  <p>This is where the docs end. I'm now trying to figure out how to insert, update, or delete a <code>Playlist</code>.</p>
  <p>I tried defining functions in the Dao which take a <code>Playlist</code> as an argument and are annotated with <code>@Insert</code>, <code>@Update</code>, or <code>@Delete</code>, but they give me the following error:</p>
  <blockquote>
  <p>error: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
  com.user.musicplayer.models.entities.Playlist playlist</p>
  </blockquote>
  <p>I'm unsure where to go from here. If someone could refer me to a resource that could help me out or give an implementation that works, that would be much appreciated.</p>