thiagolocatelli / parse4j

Java Library to deal with Parse (parse.com) REST API
http://thiagolocatelli.github.io/parse4j
143 stars 117 forks source link

ParseQuery and ParseObject with ParseFile #6

Open drmillan opened 10 years ago

drmillan commented 10 years ago

Hello, I am trying to query a list of objects which contains a ParseFile, this is the failing code: ParseQuery query=ParseQuery.getQuery("file_test"); System.out.println(query.find().size());

I am getting this exception: Exception in thread "main" java.lang.IllegalArgumentException: ParseFile must be saved before being set on a ParseObject. at org.parse4j.ParseObject.put(ParseObject.java:359)

Maybe find setData method should not be doing same validations as when we are creating the objects, I may be wrong on this :P

thiagolocatelli commented 10 years ago

You need to save the parse object before you use it inside another one

On Sunday, April 6, 2014, Daniel Rodríguez Millán notifications@github.com wrote:

Hello, I am trying to query a list of objects which contains a ParseFile, this is the failing code: ParseQuery query=ParseQuery.getQuery("file_test"); System.out.println(query.find().size());

I am getting this exception: Exception in thread "main" java.lang.IllegalArgumentException: ParseFile must be saved before being set on a ParseObject. at org.parse4j.ParseObject.put(ParseObject.java:359)

Maybe find setData method should not be doing same validations as when we are creating the objects, I may be wrong on this :P

Reply to this email directly or view it on GitHubhttps://github.com/thiagolocatelli/parse4j/issues/6 .

"thiago:locatelli$gmail:com".replace(':','.').replace('$','@')

drmillan commented 10 years ago

I don´t have access to the object at that moment, that is the only code in the app (apart from initialization), only a query over an entity so i don't have any previous ParseObject created.

aguyngueran commented 10 years ago

I struggle with the same problem as well. I try to retrieve the existing objects that contain ParseFile column. The problem is inside ParseDecoder.decode which for incoming files:

    if (typeString.equals("File")) {
        return new ParseFile(jsonObject.optString("name"),
                jsonObject.optString("url"));
    }

uses the following constructor:

public ParseFile(String name, String url) {
    this.name = name;
    this.url = url;
}

This leaves all "deserialized" files in dirty state and causes problems. Any chance that it will be fixed soon?

StijnQ commented 9 years ago

I'm also getting this error when trying to query ParseObjects that contain ParseFiles. Will this be fixed, or is there a another way to handle this?

aguyngueran commented 9 years ago

What I did for my project was to change:

public ParseFile(String name, String url) {
    this.name = name;
    this.url = url;
}

into this:

public ParseFile(String name, String url) {
    this.name = name;
    this.url = url;
    this.dirty = false;
    this.uplodated = true;
}
aguyngueran commented 9 years ago

Personally, I have downloaded Parse4j sources and included it in my project. As far as I remember there were few other changes to this library as well.

aperritano commented 9 years ago

Hi, I'm having this same problem. Is there a better work around then changing the source? I'm using this library from a mvn jar.

i ParseRelation pItems = getRelation("PItems"); ParseQuery fetchQuery = pItems.getQuery();

    List<PItem> allPItems = null;
    try {
        allPItems = fetchQuery.find();
    } catch (ParseException e) {
        e.printStackTrace();
    }

Exception in thread "pool-1-thread-1" java.lang.IllegalArgumentException: ParseFile must be saved before being set on a ParseObject. at org.parse4j.ParseObject.put(ParseObject.java:359) at org.parse4j.ParseObject.setData(ParseObject.java:725) at org.parse4j.ParseQuery.find(ParseQuery.java:499)

why is it trying to set an object when I'm trying to do a query?