Ghost
Ghost

Reputation: 340

HashMap from Room Persistance Library

I want to get a key-pair object from my sql, so how can I make sometime like this

@Query("SELECT id,name FROM table")
HashMap<Integer, String> getValues();

Upvotes: 5

Views: 4327

Answers (1)

Levi Moreira
Levi Moreira

Reputation: 12005

You better off creating a Pojo to encapsulate your pair, that's the way they do in the samples, which I imagine is the right way to do it.

class  POJO {
    String name;
    int id;
}

@Query("SELECT id,name FROM table")
List<POJO> getValues();

Upvotes: 6

Related Questions