Start a new topic

getEntity() returns null all the time

hello,


I am having a problem with fetching an entity. I attached my snippet below.

I created an unique id for my entity.  Saving an entity was successful. I could see in Kinvey console that the entity was perfectly saved in the way that I wanted.


However, I have been struggling with fetching.  Every time I retrieve an entity using getEntity() method, I get only null value. As you can see from the below code, my code is pretty much the same as the code in the Kinvey guide. I also included empty public constructor in my entity class.  I am not sure why I am getting a null value.  


@Override
public void saveEntity() {
myEntity.setID("temporaryID"); //assign unique ID to myEntity
myAppData.save(myEntity, new KinveyClientCallback<myEntity>() {
@Override
public void onSuccess(myEntity savedEntity) {
Log.i(LOG_TAG, "The entity is successfully saved");
}

@Override
public void onFailure(Throwable e) {
Log.e(LOG_TAG, "Entity saving has failed", e);
}
});
}


@Override
public void loadEntity(){
myAppData = mKinveyClient.appData("myCollection", myEntity.class);
String id = "temporaryID";
myAppData.getEntity(id, new KinveyClientCallback<myEntity>() {
@Override
public void onSuccess(myEntity fetchedEntity) {
if(fetchedEntity != null) {
Log.i(LOG_TAG, "The entity is successfully loaded: ");
}else{
Log.e(LOG_TAG, "The fetch entity is null");
}
}

@Override
public void onFailure(Throwable e) {
Log.e(LOG_TAG, "Entity loading has failed", e);
}
});
}

I could fix this problem by making my entity class 'public'


The entity class need to be visible from the outside. Otherwise fetching existing entities will return null value all the time.

Kyungsuk,


What is the user that you are using to execute these queries?  Entities can only be fetched by the user that owns them, created them (thus is the owner from an ACL perspective), has been manually added to the acl, or is authenticated as Master-Secret.   If you are authenticated using app-secret that cannot query as it does not have access to anything other than creating users I believe.  


Can you please clarify that the user authenticated appears in the ACL of the object it's trying to fetch?


Thanks,

Hello, Damien


When fetching entities, I used the same user who created those entities.  The user had access to the entities.

I was puzzled at first why my queries only returned null values with the access, but I could manage to fix my problem.


I fixed the problem by redefining my entity class(which extends the genericJson class) as a public class.

Originally it was not declared as a public class and it was visible inside the package only.


Login or Signup to post a comment