How to make composite key in Room

Make use of primaryKeys().

Android Developer Documentation for Room states:

If PrimaryKey annotation is used on a Embeddedd field, all columns
inherited from that embedded field becomes the composite primary key
(including its grand children fields).

Example implementation in Java:

@Entity(primaryKeys = {"column1","column2","column3"})
public class DummyClass {
    ...
}

Example implementation in kotlin:

@Entity(primaryKeys = ["column1","column2","column3"])
class DummyClass {
    ...
}

Thanks Lalit Kushwah for the example.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)