title: Joining tables in a ROOM database
body: <p>This is my first ROOM implementation. I have a <strong>User</strong> class which has a list of <strong>Pets</strong> as one of its member variables.</p>
  
  <pre><code>public class User {
      String id;
      String name;
      List&lt;Pet&gt; pets;
  }
  
  
  Public class Pets {
      String id;
      String type;
  }
  </code></pre>
  
  <p>How to create its Entity and DAO classes for Room Database from the following JSON?</p>
  
  <pre><code>{  
    "users":[  
      {  
        "id":"as123",
        "name":"John",
        "pets":[  
          {  
            "id":"p123",
            "type":"dog"
          }
        ]
      },
      {  
        "id":"as343",
        "name":"Mark",
        "pets":[  
          {  
            "id":"p324",
            "type":"dog"
          },
          {  
            "id":"p254",
            "type":"cat"
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>I have created the following but not sure how to create a correct column or Join these tables.</p>
  
  <p><strong>Entity Classes</strong></p>
  
  <pre><code>@Entity(tableName = "user")
  public class User {
  
      @PrimaryKey
      @NonNull
      @ColumnInfo(name = "id")
      String id;
  
      @Nullable
      @ColumnInfo(name = "name")
      String name;
  
      List&lt;Pets&gt; pets; // how to set type for Pets
  }
  
  @Entity(tableName = "pets",
      foreignKeys = @ForeignKey(entity = User.class,
      parentColumns = "id",
      childColumns = "userId",
      onDelete = CASCADE))
  Public class Pets {
  
      @PrimaryKey
      @NonNull
      @ColumnInfo(name = "id")
      String id;
  
      @Nullable
      @ColumnInfo(name = "type")
      String type;
  
      @NonNull
      @ColumnInfo(name = "userId")
      String userId; // for accessing pets of a user
  } 
  </code></pre>
  
  <p><strong>DAO classes</strong></p>
  
  <pre><code>@Dao
  public interface PetsDAO {
  
      @Insert
      void insert(Pets pets);
  
      @Update
      void update(Pets... pets);
  
      @Delete
      void delete(Pets... pets);
  
      @Query("SELECT * FROM pets WHERE id=:userId")
      List&lt;Pets&gt; getPetsForUser(final String userId);
  }
  
  @Dao
  public interface UserDAO {
  
      @Insert
      void insert(User pets);
  
      @Update
      void update(User... pets);
  
      @Delete
      void delete(User... pets);
  
      @Query("SELECT * FROM user)
      List&lt;User&gt; getAllUsers(); // should return list of users with all their pets
  }
  </code></pre>
  
  <p>How can I get a <code>List</code> of users with all of their respective pets?</p>