Android Room, can only get 1 result from query but checked and there should be more










0















I checked the database, there should be 4 results with the same group. I checked the insertion everything works fine.



@Dao
public interface MemberDao
@Query("Select * from `Member` where id=:groupsId")
List<Member> getMembers(int groupsId);



Here is my method to retrieve data,



public List<Member> getMembers(final Group group)
LoadData d = new LoadData();
d.onComplete = this;
d.execute(group);

return null;


@Override
public void onOutput(List<Member> result)
member = result;
for(Member m : member)
System.out.println(m.name);



public class LoadData extends AsyncTask<Group, Void, List<Member>>
private OnTaskComplete onComplete =null;

@Override
protected List<Member> doInBackground(Group... groups)
List<Member> result = memberDao.getMembers(groups[0].id);
return result;


@Override
protected void onPostExecute(List<Member> result)
onComplete.onOutput(result);





But the result only has 1 in it and there should be 4 member in the List.



so My question is:



  1. if I can get 1 result back, the groupsId is not a problem.
    So why does it only return 1 result?


  2. I try to just return the whole list of member regardless of the groupsId, and I can get exactly 4 back. So it only happens when I try to specify a groups Id.


Does someone know why it behaves like that ?



P.S. Here is the Member class.



@Entity(foreignKeys = @ForeignKey(parentColumns =
"id", childColumns = "groupsId", entity = Group.class))
public class Member {
@PrimaryKey(autoGenerate = true)
public int id;
public String name;
public long groupsId;

public Member(String name)
this.name = name;


public void setGroupsId(long groupsId)
this.groupsId = groupsId;


public String getName()
return name;



enter image description here
I posted it here to show the verified data.










share|improve this question
























  • I verified. The data is correct.

    – Rex Yu
    Nov 14 '18 at 20:19











  • sorry, I dont understand. Does it mean to dump the result to a cursor instead of List<Member>?

    – Rex Yu
    Nov 14 '18 at 20:46











  • yes, see DatabaseUtils#dumpCursor

    – pskink
    Nov 14 '18 at 20:47











  • D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@5f25918 0 id=1 name=user1 groupsId=1 1 id=2 name=user2 groupsId=1 <<<<< Here is the cursor result I reset the database and added 2 members in group, when I switch to use a GroupId with the query. it gives me this.

    – Rex Yu
    Nov 14 '18 at 21:35












  • D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@e443078 0 id=1 name=user1 groupsId=1 <<<<<

    – Rex Yu
    Nov 14 '18 at 21:38















0















I checked the database, there should be 4 results with the same group. I checked the insertion everything works fine.



@Dao
public interface MemberDao
@Query("Select * from `Member` where id=:groupsId")
List<Member> getMembers(int groupsId);



Here is my method to retrieve data,



public List<Member> getMembers(final Group group)
LoadData d = new LoadData();
d.onComplete = this;
d.execute(group);

return null;


@Override
public void onOutput(List<Member> result)
member = result;
for(Member m : member)
System.out.println(m.name);



public class LoadData extends AsyncTask<Group, Void, List<Member>>
private OnTaskComplete onComplete =null;

@Override
protected List<Member> doInBackground(Group... groups)
List<Member> result = memberDao.getMembers(groups[0].id);
return result;


@Override
protected void onPostExecute(List<Member> result)
onComplete.onOutput(result);





But the result only has 1 in it and there should be 4 member in the List.



so My question is:



  1. if I can get 1 result back, the groupsId is not a problem.
    So why does it only return 1 result?


  2. I try to just return the whole list of member regardless of the groupsId, and I can get exactly 4 back. So it only happens when I try to specify a groups Id.


Does someone know why it behaves like that ?



P.S. Here is the Member class.



@Entity(foreignKeys = @ForeignKey(parentColumns =
"id", childColumns = "groupsId", entity = Group.class))
public class Member {
@PrimaryKey(autoGenerate = true)
public int id;
public String name;
public long groupsId;

public Member(String name)
this.name = name;


public void setGroupsId(long groupsId)
this.groupsId = groupsId;


public String getName()
return name;



enter image description here
I posted it here to show the verified data.










share|improve this question
























  • I verified. The data is correct.

    – Rex Yu
    Nov 14 '18 at 20:19











  • sorry, I dont understand. Does it mean to dump the result to a cursor instead of List<Member>?

    – Rex Yu
    Nov 14 '18 at 20:46











  • yes, see DatabaseUtils#dumpCursor

    – pskink
    Nov 14 '18 at 20:47











  • D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@5f25918 0 id=1 name=user1 groupsId=1 1 id=2 name=user2 groupsId=1 <<<<< Here is the cursor result I reset the database and added 2 members in group, when I switch to use a GroupId with the query. it gives me this.

    – Rex Yu
    Nov 14 '18 at 21:35












  • D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@e443078 0 id=1 name=user1 groupsId=1 <<<<<

    – Rex Yu
    Nov 14 '18 at 21:38













0












0








0








I checked the database, there should be 4 results with the same group. I checked the insertion everything works fine.



@Dao
public interface MemberDao
@Query("Select * from `Member` where id=:groupsId")
List<Member> getMembers(int groupsId);



Here is my method to retrieve data,



public List<Member> getMembers(final Group group)
LoadData d = new LoadData();
d.onComplete = this;
d.execute(group);

return null;


@Override
public void onOutput(List<Member> result)
member = result;
for(Member m : member)
System.out.println(m.name);



public class LoadData extends AsyncTask<Group, Void, List<Member>>
private OnTaskComplete onComplete =null;

@Override
protected List<Member> doInBackground(Group... groups)
List<Member> result = memberDao.getMembers(groups[0].id);
return result;


@Override
protected void onPostExecute(List<Member> result)
onComplete.onOutput(result);





But the result only has 1 in it and there should be 4 member in the List.



so My question is:



  1. if I can get 1 result back, the groupsId is not a problem.
    So why does it only return 1 result?


  2. I try to just return the whole list of member regardless of the groupsId, and I can get exactly 4 back. So it only happens when I try to specify a groups Id.


Does someone know why it behaves like that ?



P.S. Here is the Member class.



@Entity(foreignKeys = @ForeignKey(parentColumns =
"id", childColumns = "groupsId", entity = Group.class))
public class Member {
@PrimaryKey(autoGenerate = true)
public int id;
public String name;
public long groupsId;

public Member(String name)
this.name = name;


public void setGroupsId(long groupsId)
this.groupsId = groupsId;


public String getName()
return name;



enter image description here
I posted it here to show the verified data.










share|improve this question
















I checked the database, there should be 4 results with the same group. I checked the insertion everything works fine.



@Dao
public interface MemberDao
@Query("Select * from `Member` where id=:groupsId")
List<Member> getMembers(int groupsId);



Here is my method to retrieve data,



public List<Member> getMembers(final Group group)
LoadData d = new LoadData();
d.onComplete = this;
d.execute(group);

return null;


@Override
public void onOutput(List<Member> result)
member = result;
for(Member m : member)
System.out.println(m.name);



public class LoadData extends AsyncTask<Group, Void, List<Member>>
private OnTaskComplete onComplete =null;

@Override
protected List<Member> doInBackground(Group... groups)
List<Member> result = memberDao.getMembers(groups[0].id);
return result;


@Override
protected void onPostExecute(List<Member> result)
onComplete.onOutput(result);





But the result only has 1 in it and there should be 4 member in the List.



so My question is:



  1. if I can get 1 result back, the groupsId is not a problem.
    So why does it only return 1 result?


  2. I try to just return the whole list of member regardless of the groupsId, and I can get exactly 4 back. So it only happens when I try to specify a groups Id.


Does someone know why it behaves like that ?



P.S. Here is the Member class.



@Entity(foreignKeys = @ForeignKey(parentColumns =
"id", childColumns = "groupsId", entity = Group.class))
public class Member {
@PrimaryKey(autoGenerate = true)
public int id;
public String name;
public long groupsId;

public Member(String name)
this.name = name;


public void setGroupsId(long groupsId)
this.groupsId = groupsId;


public String getName()
return name;



enter image description here
I posted it here to show the verified data.







android android-room






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 3:12







Rex Yu

















asked Nov 14 '18 at 19:14









Rex YuRex Yu

165




165












  • I verified. The data is correct.

    – Rex Yu
    Nov 14 '18 at 20:19











  • sorry, I dont understand. Does it mean to dump the result to a cursor instead of List<Member>?

    – Rex Yu
    Nov 14 '18 at 20:46











  • yes, see DatabaseUtils#dumpCursor

    – pskink
    Nov 14 '18 at 20:47











  • D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@5f25918 0 id=1 name=user1 groupsId=1 1 id=2 name=user2 groupsId=1 <<<<< Here is the cursor result I reset the database and added 2 members in group, when I switch to use a GroupId with the query. it gives me this.

    – Rex Yu
    Nov 14 '18 at 21:35












  • D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@e443078 0 id=1 name=user1 groupsId=1 <<<<<

    – Rex Yu
    Nov 14 '18 at 21:38

















  • I verified. The data is correct.

    – Rex Yu
    Nov 14 '18 at 20:19











  • sorry, I dont understand. Does it mean to dump the result to a cursor instead of List<Member>?

    – Rex Yu
    Nov 14 '18 at 20:46











  • yes, see DatabaseUtils#dumpCursor

    – pskink
    Nov 14 '18 at 20:47











  • D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@5f25918 0 id=1 name=user1 groupsId=1 1 id=2 name=user2 groupsId=1 <<<<< Here is the cursor result I reset the database and added 2 members in group, when I switch to use a GroupId with the query. it gives me this.

    – Rex Yu
    Nov 14 '18 at 21:35












  • D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@e443078 0 id=1 name=user1 groupsId=1 <<<<<

    – Rex Yu
    Nov 14 '18 at 21:38
















I verified. The data is correct.

– Rex Yu
Nov 14 '18 at 20:19





I verified. The data is correct.

– Rex Yu
Nov 14 '18 at 20:19













sorry, I dont understand. Does it mean to dump the result to a cursor instead of List<Member>?

– Rex Yu
Nov 14 '18 at 20:46





sorry, I dont understand. Does it mean to dump the result to a cursor instead of List<Member>?

– Rex Yu
Nov 14 '18 at 20:46













yes, see DatabaseUtils#dumpCursor

– pskink
Nov 14 '18 at 20:47





yes, see DatabaseUtils#dumpCursor

– pskink
Nov 14 '18 at 20:47













D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@5f25918 0 id=1 name=user1 groupsId=1 1 id=2 name=user2 groupsId=1 <<<<< Here is the cursor result I reset the database and added 2 members in group, when I switch to use a GroupId with the query. it gives me this.

– Rex Yu
Nov 14 '18 at 21:35






D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@5f25918 0 id=1 name=user1 groupsId=1 1 id=2 name=user2 groupsId=1 <<<<< Here is the cursor result I reset the database and added 2 members in group, when I switch to use a GroupId with the query. it gives me this.

– Rex Yu
Nov 14 '18 at 21:35














D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@e443078 0 id=1 name=user1 groupsId=1 <<<<<

– Rex Yu
Nov 14 '18 at 21:38





D/database: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@e443078 0 id=1 name=user1 groupsId=1 <<<<<

– Rex Yu
Nov 14 '18 at 21:38












1 Answer
1






active

oldest

votes


















0














add room annotations:



public class Member 

@ColumnInfo(name = "user_id")
@PrimaryKey(autoGenerate = true)
private Long userId;

@ColumnInfo(name = "group_id")
private Long groupId;

@ColumnInfo(name = "username")
public String name;

...






share|improve this answer























  • I tried and it still behaves the same

    – Rex Yu
    Nov 14 '18 at 20:20










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307279%2fandroid-room-can-only-get-1-result-from-query-but-checked-and-there-should-be-m%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














add room annotations:



public class Member 

@ColumnInfo(name = "user_id")
@PrimaryKey(autoGenerate = true)
private Long userId;

@ColumnInfo(name = "group_id")
private Long groupId;

@ColumnInfo(name = "username")
public String name;

...






share|improve this answer























  • I tried and it still behaves the same

    – Rex Yu
    Nov 14 '18 at 20:20















0














add room annotations:



public class Member 

@ColumnInfo(name = "user_id")
@PrimaryKey(autoGenerate = true)
private Long userId;

@ColumnInfo(name = "group_id")
private Long groupId;

@ColumnInfo(name = "username")
public String name;

...






share|improve this answer























  • I tried and it still behaves the same

    – Rex Yu
    Nov 14 '18 at 20:20













0












0








0







add room annotations:



public class Member 

@ColumnInfo(name = "user_id")
@PrimaryKey(autoGenerate = true)
private Long userId;

@ColumnInfo(name = "group_id")
private Long groupId;

@ColumnInfo(name = "username")
public String name;

...






share|improve this answer













add room annotations:



public class Member 

@ColumnInfo(name = "user_id")
@PrimaryKey(autoGenerate = true)
private Long userId;

@ColumnInfo(name = "group_id")
private Long groupId;

@ColumnInfo(name = "username")
public String name;

...







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 19:49









Martin ZeitlerMartin Zeitler

17.7k34270




17.7k34270












  • I tried and it still behaves the same

    – Rex Yu
    Nov 14 '18 at 20:20

















  • I tried and it still behaves the same

    – Rex Yu
    Nov 14 '18 at 20:20
















I tried and it still behaves the same

– Rex Yu
Nov 14 '18 at 20:20





I tried and it still behaves the same

– Rex Yu
Nov 14 '18 at 20:20



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307279%2fandroid-room-can-only-get-1-result-from-query-but-checked-and-there-should-be-m%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto